diff --git a/build/releasenotes.props b/build/releasenotes.props index 4f57e2a4..93f2c552 100644 --- a/build/releasenotes.props +++ b/build/releasenotes.props @@ -1,20 +1,19 @@ - 1. Expose raw cache database. + 1. Upgrading dependencies. - 1. Expose raw cache database. + 1. Upgrading dependencies. - 1. Expose raw cache database. - 2. Support KeyPrefix. + 1. Fix removebyprefix when enable keyprefix. - 1. Expose raw cache database. + 1. Upgrading dependencies. - 1. Expose raw cache database. + 1. Upgrading dependencies. 1. Upgrading dependencies. @@ -38,7 +37,7 @@ 1. Upgrading dependencies. - 1. Support distributed lock. + 1. Upgrading dependencies. 1. Upgrading dependencies. @@ -47,13 +46,13 @@ 1. Upgrading dependencies. - 1. Upgrading dependencies. - + 1. Allow user to define client provided name. + 1. Upgrading dependencies. - 1. Expose raw cache database. + 1. Upgrading dependencies. 1. Upgrading dependencies. diff --git a/build/version.props b/build/version.props index 05037d68..2ad801b0 100644 --- a/build/version.props +++ b/build/version.props @@ -1,24 +1,24 @@ - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 - 1.5.0 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 + 1.5.1 diff --git a/bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs b/bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs index cc8eec84..72e6ad84 100644 --- a/bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs +++ b/bus/EasyCaching.Bus.RabbitMQ/DefaultRabbitMQBus.cs @@ -64,7 +64,8 @@ IPooledObjectPolicy _objectPolicy VirtualHost = _options.VirtualHost, RequestedConnectionTimeout = System.TimeSpan.FromMilliseconds(_options.RequestedConnectionTimeout), SocketReadTimeout = System.TimeSpan.FromMilliseconds(_options.SocketReadTimeout), - SocketWriteTimeout = System.TimeSpan.FromMilliseconds(_options.SocketWriteTimeout) + SocketWriteTimeout = System.TimeSpan.FromMilliseconds(_options.SocketWriteTimeout), + ClientProvidedName = _options.ClientProvidedName }; _subConnection = factory.CreateConnection(); diff --git a/docs/Hybrid.md b/docs/Hybrid.md index 17fb1fd0..3552a2eb 100644 --- a/docs/Hybrid.md +++ b/docs/Hybrid.md @@ -34,6 +34,8 @@ public class Startup services.AddEasyCaching(option => { + option.WithJson("myjson"); + // local option.UseInMemory("m1"); // distributed @@ -41,6 +43,7 @@ public class Startup { config.DBConfig.Endpoints.Add(new Core.Configurations.ServerEndPoint("127.0.0.1", 6379)); config.DBConfig.Database = 5; + config.SerializerName = "myjson"; }, "myredis"); // combine local and distributed @@ -58,6 +61,9 @@ public class Startup .WithRedisBus(busConf => { busConf.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380)); + + // do not forget to set the SerializerName for the bus here !! + busConf.SerializerName = "myjson"; }); }); } diff --git a/src/EasyCaching.Core/Configurations/BaseRabbitMQOptions.cs b/src/EasyCaching.Core/Configurations/BaseRabbitMQOptions.cs index aae147f1..eec55588 100644 --- a/src/EasyCaching.Core/Configurations/BaseRabbitMQOptions.cs +++ b/src/EasyCaching.Core/Configurations/BaseRabbitMQOptions.cs @@ -51,5 +51,10 @@ public class BaseRabbitMQOptions /// Gets or sets queue message automatic deletion time (in milliseconds). Default 864000000 ms (10 days). /// public int QueueMessageExpires { get; set; } = 864000000; + + /// + /// Gets or sets the client-provided name for the rabbit connection. Default null (handled by rabbit client) + /// + public string ClientProvidedName { get; set; } } } diff --git a/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs b/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs index 50a9fb22..215d39e6 100644 --- a/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs +++ b/src/EasyCaching.Redis/DefaultRedisCachingProvider.cs @@ -304,6 +304,11 @@ private RedisKey[] SearchRedisKeys(string pattern) // from this redis dev specification, https://yq.aliyun.com/articles/531067 , maybe the appropriate scope is 100~500, using 200 here. keys.AddRange(server.Keys(pattern: pattern, database: _cache.Database, pageSize: 200)); + if (!string.IsNullOrWhiteSpace(_options.DBConfig.KeyPrefix)) + keys = keys.Select(x => new RedisKey( + x.ToString().Remove(0, _options.DBConfig.KeyPrefix.Length))) + .ToList(); + return keys.Distinct().ToArray(); //var keys = new HashSet(); @@ -343,6 +348,9 @@ private string HandlePrefix(string prefix) if (!prefix.EndsWith("*", StringComparison.OrdinalIgnoreCase)) prefix = string.Concat(prefix, "*"); + if (!string.IsNullOrWhiteSpace(_options.DBConfig.KeyPrefix)) + prefix = _options.DBConfig.KeyPrefix + prefix; + return prefix; } diff --git a/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs b/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs index 4c963a57..6fe66aef 100644 --- a/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs +++ b/test/EasyCaching.UnitTests/CachingTests/RedisCachingProviderTest.cs @@ -272,5 +272,28 @@ public void KeyPrefixTest() var val3 = WithKeyPrefix.Get("KeyPrefix"); Assert.Equal(val1.Value, val3.Value); } + + [Fact] + public void RemoveByPrefixTest() + { + var WithKeyPrefix = _providerFactory.GetCachingProvider("WithKeyPrefix"); + + WithKeyPrefix.Set("KeyPrefix1", "ok", TimeSpan.FromSeconds(10)); + WithKeyPrefix.Set("KeyPrefix2", "ok", TimeSpan.FromSeconds(10)); + + var val1 = WithKeyPrefix.Get("KeyPrefix1"); + var val2 = WithKeyPrefix.Get("KeyPrefix2"); + + Assert.True(val1.HasValue); + Assert.True(val2.HasValue); + Assert.Equal(val1.Value, val2.Value); + + WithKeyPrefix.RemoveByPrefix("Key"); + + var val3 = WithKeyPrefix.Get("KeyPrefix1"); + var val4 = WithKeyPrefix.Get("KeyPrefix2"); + Assert.False(val3.HasValue); + Assert.False(val4.HasValue); + } } } \ No newline at end of file