diff --git a/CacheTower.sln b/CacheTower.sln
index 1e73a7e..726fe88 100644
--- a/CacheTower.sln
+++ b/CacheTower.sln
@@ -45,7 +45,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CacheTower.Serializers.Newt
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CacheTower.Serializers.Protobuf", "src\CacheTower.Serializers.Protobuf\CacheTower.Serializers.Protobuf.csproj", "{436A6DF0-3DD8-4342-ACC5-EF0B8D5DF9DD}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CacheTower.Serializers.SystemTextJson", "src\CacheTower.Serializers.SystemTextJson\CacheTower.Serializers.SystemTextJson.csproj", "{4E94E3E8-3CC0-4F23-BFD7-157C8C386AFB}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CacheTower.Serializers.SystemTextJson", "src\CacheTower.Serializers.SystemTextJson\CacheTower.Serializers.SystemTextJson.csproj", "{4E94E3E8-3CC0-4F23-BFD7-157C8C386AFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/src/CacheTower.Extensions.Redis/CacheTower.Extensions.Redis.csproj b/src/CacheTower.Extensions.Redis/CacheTower.Extensions.Redis.csproj
index 9107c91..4dcb084 100644
--- a/src/CacheTower.Extensions.Redis/CacheTower.Extensions.Redis.csproj
+++ b/src/CacheTower.Extensions.Redis/CacheTower.Extensions.Redis.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/src/CacheTower.Extensions.Redis/RedisLockExtension.cs b/src/CacheTower.Extensions.Redis/RedisLockExtension.cs
index 69ecb99..27ca21d 100644
--- a/src/CacheTower.Extensions.Redis/RedisLockExtension.cs
+++ b/src/CacheTower.Extensions.Redis/RedisLockExtension.cs
@@ -45,7 +45,7 @@ public RedisLockExtension(IConnectionMultiplexer connection, RedisLockOptions op
LockedOnKeyRefresh = new ConcurrentDictionary>(StringComparer.Ordinal);
- Subscriber.Subscribe(options.RedisChannel, (channel, value) =>
+ Subscriber.Subscribe(GetRedisChannel(), (channel, value) =>
{
if (!value.IsNull)
{
@@ -54,6 +54,8 @@ public RedisLockExtension(IConnectionMultiplexer connection, RedisLockOptions op
});
}
+ private RedisChannel GetRedisChannel() => new(Options.RedisChannel, RedisChannel.PatternMode.Auto);
+
///
public void Register(ICacheStack cacheStack)
{
@@ -68,7 +70,7 @@ public void Register(ICacheStack cacheStack)
private async ValueTask ReleaseLockAsync(string cacheKey)
{
var lockKey = string.Format(Options.KeyFormat, cacheKey);
- await Subscriber.PublishAsync(Options.RedisChannel, cacheKey, CommandFlags.FireAndForget);
+ await Subscriber.PublishAsync(GetRedisChannel(), cacheKey, CommandFlags.FireAndForget);
await Database.KeyDeleteAsync(lockKey, CommandFlags.FireAndForget);
UnlockWaitingTasks(cacheKey);
}
diff --git a/src/CacheTower.Extensions.Redis/RedisRemoteEvictionExtension.cs b/src/CacheTower.Extensions.Redis/RedisRemoteEvictionExtension.cs
index 7f1c5fa..7c9d87b 100644
--- a/src/CacheTower.Extensions.Redis/RedisRemoteEvictionExtension.cs
+++ b/src/CacheTower.Extensions.Redis/RedisRemoteEvictionExtension.cs
@@ -12,8 +12,8 @@ namespace CacheTower.Extensions.Redis
public class RedisRemoteEvictionExtension : ICacheChangeExtension
{
private ISubscriber Subscriber { get; }
- private string FlushChannel { get; }
- private string EvictionChannel { get; }
+ private RedisChannel FlushChannel { get; }
+ private RedisChannel EvictionChannel { get; }
private bool IsRegistered { get; set; }
@@ -39,8 +39,8 @@ public RedisRemoteEvictionExtension(IConnectionMultiplexer connection, string ch
}
Subscriber = connection.GetSubscriber();
- FlushChannel = $"{channelPrefix}.RemoteFlush";
- EvictionChannel = $"{channelPrefix}.RemoteEviction";
+ FlushChannel = new($"{channelPrefix}.RemoteFlush", RedisChannel.PatternMode.Auto);
+ EvictionChannel = new($"{channelPrefix}.RemoteEviction", RedisChannel.PatternMode.Auto);
FlaggedEvictions = new HashSet(StringComparer.Ordinal);
}
diff --git a/src/CacheTower.Providers.Redis/CacheTower.Providers.Redis.csproj b/src/CacheTower.Providers.Redis/CacheTower.Providers.Redis.csproj
index f6099f0..6b40198 100644
--- a/src/CacheTower.Providers.Redis/CacheTower.Providers.Redis.csproj
+++ b/src/CacheTower.Providers.Redis/CacheTower.Providers.Redis.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/src/CacheTower.Providers.Redis/RedisCacheLayer.cs b/src/CacheTower.Providers.Redis/RedisCacheLayer.cs
index cb8e425..7fb03e5 100644
--- a/src/CacheTower.Providers.Redis/RedisCacheLayer.cs
+++ b/src/CacheTower.Providers.Redis/RedisCacheLayer.cs
@@ -75,10 +75,8 @@ public async ValueTask FlushAsync()
var redisValue = await Database.StringGetAsync(cacheKey);
if (redisValue != RedisValue.Null)
{
- using (var stream = new MemoryStream(redisValue))
- {
- return Options.Serializer.Deserialize>(stream);
- }
+ using var stream = new MemoryStream(redisValue);
+ return Options.Serializer.Deserialize>(stream);
}
return default;
@@ -99,13 +97,11 @@ public async ValueTask SetAsync(string cacheKey, CacheEntry cacheEntry)
return;
}
- using (var stream = new MemoryStream())
- {
- Options.Serializer.Serialize(stream, cacheEntry);
- stream.Seek(0, SeekOrigin.Begin);
- var redisValue = RedisValue.CreateFrom(stream);
- await Database.StringSetAsync(cacheKey, redisValue, expiryOffset);
- }
+ using var stream = new MemoryStream();
+ Options.Serializer.Serialize(stream, cacheEntry);
+ stream.Seek(0, SeekOrigin.Begin);
+ var redisValue = RedisValue.CreateFrom(stream);
+ await Database.StringSetAsync(cacheKey, redisValue, expiryOffset);
}
}
}
diff --git a/tests/CacheTower.Tests/Extensions/Redis/RedisLockExtensionTests.cs b/tests/CacheTower.Tests/Extensions/Redis/RedisLockExtensionTests.cs
index 819b47e..1c73b6e 100644
--- a/tests/CacheTower.Tests/Extensions/Redis/RedisLockExtensionTests.cs
+++ b/tests/CacheTower.Tests/Extensions/Redis/RedisLockExtensionTests.cs
@@ -74,7 +74,7 @@ public async Task RefreshValueNotifiesChannelSubscribers()
var completionSource = new TaskCompletionSource();
- await connection.GetSubscriber().SubscribeAsync("CacheTower.CacheLock", (channel, value) =>
+ await connection.GetSubscriber().SubscribeAsync(new("CacheTower.CacheLock", RedisChannel.PatternMode.Literal), (channel, value) =>
{
if (value == "TestKey")
{
@@ -126,7 +126,7 @@ public async Task ObservedLockSingle()
Assert.IsTrue(extension.LockedOnKeyRefresh.ContainsKey("TestKey"), "Lock was not established");
//Trigger the end of the lock
- await connection.GetSubscriber().PublishAsync("CacheTower.CacheLock", "TestKey");
+ await connection.GetSubscriber().PublishAsync(new("CacheTower.CacheLock", RedisChannel.PatternMode.Literal), "TestKey");
var succeedingTask = await Task.WhenAny(lockTask, Task.Delay(TimeSpan.FromSeconds(10)));
if (!succeedingTask.Equals(lockTask))
@@ -160,7 +160,7 @@ public async Task ObservedLockMultiple()
Assert.IsTrue(extension.LockedOnKeyRefresh.ContainsKey("TestKey"), "Lock was not established");
//Trigger the end of the lock
- await connection.GetSubscriber().PublishAsync("CacheTower.CacheLock", "TestKey");
+ await connection.GetSubscriber().PublishAsync(new("CacheTower.CacheLock", RedisChannel.PatternMode.Literal), "TestKey");
var whenAllRefreshesTask = Task.WhenAll(lockTask1, lockTask2);
var succeedingTask = await Task.WhenAny(whenAllRefreshesTask, Task.Delay(TimeSpan.FromSeconds(10)));
diff --git a/tests/CacheTower.Tests/Extensions/Redis/RedisRemoteEvictionExtensionTests.cs b/tests/CacheTower.Tests/Extensions/Redis/RedisRemoteEvictionExtensionTests.cs
index ef15f8c..68ab689 100644
--- a/tests/CacheTower.Tests/Extensions/Redis/RedisRemoteEvictionExtensionTests.cs
+++ b/tests/CacheTower.Tests/Extensions/Redis/RedisRemoteEvictionExtensionTests.cs
@@ -60,7 +60,7 @@ public async Task RemoteEvictionOccursOnRefresh()
extensionTwo.Register(cacheStackMockTwo);
var completionSource = new TaskCompletionSource();
- connection.GetSubscriber().Subscribe("CacheTower.RemoteEviction").OnMessage(channelMessage =>
+ connection.GetSubscriber().Subscribe(new("CacheTower.RemoteEviction", RedisChannel.PatternMode.Literal)).OnMessage(channelMessage =>
{
if (channelMessage.Message == "TestKey")
{
@@ -111,7 +111,7 @@ public async Task RemoteEvictionOccursOnLocalEviction()
extensionTwo.Register(cacheStackMockTwo);
var completionSource = new TaskCompletionSource();
- connection.GetSubscriber().Subscribe("CacheTower.RemoteEviction").OnMessage(channelMessage =>
+ connection.GetSubscriber().Subscribe(new("CacheTower.RemoteEviction", RedisChannel.PatternMode.Literal)).OnMessage(channelMessage =>
{
if (channelMessage.Message == "TestKey")
{
@@ -166,7 +166,7 @@ public async Task RemoteFlush()
extensionTwo.Register(cacheStackMockTwo);
var completionSource = new TaskCompletionSource();
- connection.GetSubscriber().Subscribe("CacheTower.RemoteFlush").OnMessage(channelMessage =>
+ connection.GetSubscriber().Subscribe(new("CacheTower.RemoteFlush", RedisChannel.PatternMode.Literal)).OnMessage(channelMessage =>
{
if (channelMessage.Message == StackExchange.Redis.RedisValue.EmptyString)
{
@@ -210,9 +210,9 @@ public async Task NoEvictionOnNewEntries()
var subscriberMock = Substitute.For();
subscriberMock.Subscribe(Arg.Any(), Arg.Any())
- .Returns(x => realConnection.GetSubscriber().Subscribe("DummyMessageQueue"));
+ .Returns(x => realConnection.GetSubscriber().Subscribe(new("DummyMessageQueue", RedisChannel.PatternMode.Literal)));
subscriberMock.Subscribe(Arg.Any(), Arg.Any())
- .Returns(x => realConnection.GetSubscriber().Subscribe("DummyMessageQueue"));
+ .Returns(x => realConnection.GetSubscriber().Subscribe(new("DummyMessageQueue", RedisChannel.PatternMode.Literal)));
connectionMock.GetSubscriber(Arg.Any