Skip to content

Commit

Permalink
Replace Redis channel name string using RedisChannel object.
Browse files Browse the repository at this point in the history
  • Loading branch information
Codespilot committed Jul 5, 2023
1 parent 22060f4 commit 9003d0f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Source/Euonia.Caching.Redis/RedisCacheBackplane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Nerosoft.Euonia.Caching.Redis;
public sealed class RedisCacheBackplane : CacheBackplane
{
private const int HARD_LIMIT = 50000;
private readonly string _channelName;
private readonly RedisChannel _channelName;
private readonly byte[] _identifier;
private readonly RedisConnectionManager _connection;
private readonly Timer _timer;
Expand All @@ -40,7 +40,7 @@ public RedisCacheBackplane(CacheManagerConfiguration configuration, string conne
: base(configuration)
{
Check.EnsureNotNull(configuration, nameof(configuration));
_channelName = configuration.BackplaneChannelName ?? "CacheManagerBackplane";
_channelName = new RedisChannel(configuration.BackplaneChannelName ?? "CacheManagerBackplane", RedisChannel.PatternMode.Auto);
_identifier = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());

var cfg = RedisConfigurations.GetConfiguration(ConfigurationKey, connectionString);
Expand Down
16 changes: 8 additions & 8 deletions Source/Euonia.Caching.Redis/RedisCacheHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ private CacheItem<TValue> GetCacheItemAndVersion(string key, string region, out
return cacheItem;
}

protected CacheItem<TValue> GetCacheItemInternalNoScript(string key, string region)
protected virtual CacheItem<TValue> GetCacheItemInternalNoScript(string key, string region)
{
return Retry(() =>
{
Expand Down Expand Up @@ -619,7 +619,7 @@ protected override bool RemoveInternal(string key, string region)
private void SubscribeKeyspaceNotifications()
{
_connection.Subscriber.Subscribe(
$"__keyevent@{_redisConfiguration.Database}__:expired",
new RedisChannel($"__keyevent@{_redisConfiguration.Database}__:expired", RedisChannel.PatternMode.Auto),
(_, key) =>
{
var tuple = ParseKey(key);
Expand All @@ -628,7 +628,7 @@ private void SubscribeKeyspaceNotifications()
});

_connection.Subscriber.Subscribe(
$"__keyevent@{_redisConfiguration.Database}__:evicted",
new RedisChannel($"__keyevent@{_redisConfiguration.Database}__:evicted", RedisChannel.PatternMode.Auto),
(_, key) =>
{
var tuple = ParseKey(key);
Expand All @@ -638,7 +638,7 @@ private void SubscribeKeyspaceNotifications()
});

_connection.Subscriber.Subscribe(
$"__keyevent@{_redisConfiguration.Database}__:del",
new RedisChannel($"__keyevent@{_redisConfiguration.Database}__:del", RedisChannel.PatternMode.Auto),
(_, key) =>
{
var tuple = ParseKey(key);
Expand Down Expand Up @@ -745,14 +745,14 @@ private RedisValue ToRedisValue(TValue value)
return _valueConverter.ToRedisValue(value);
}

private T Retry<T>(Func<T> retryme) =>
RetryHelper.Retry(retryme, _managerConfiguration.RetryTimeout, _managerConfiguration.MaxRetries);
private T Retry<T>(Func<T> action) =>
RetryHelper.Retry(action, _managerConfiguration.RetryTimeout, _managerConfiguration.MaxRetries);

private void Retry(Action retryme)
private void Retry(Action action)
=> Retry(
() =>
{
retryme();
action();
return true;
});

Expand Down
4 changes: 2 additions & 2 deletions Source/Euonia.Caching.Redis/RedisCacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ public TValue AddOrUpdate<TValue>(string key, TValue value, DateTime timeout, bo
/// <inheritdoc />
public TValue AddOrUpdate<TValue>(CacheItem<TValue> item)
{
var key = RewriteKey(item.Key);

return _manager.Instance<TValue>().AddOrUpdate(item, _ => item.Value);
}

Expand All @@ -109,6 +107,7 @@ public async Task<TValue> GetOrAddAsync<TValue>(string key, Func<Task<TValue>> f
{
return value;
}

value = await factory();
var result = _manager.Instance<TValue>().GetOrAdd(key, _ => GetCacheItem(key, value, timeout));
return result.Value;
Expand Down Expand Up @@ -169,6 +168,7 @@ private static CacheItem<TValue> GetCacheItem<TValue>(string key, TValue value,
{
item = new CacheItem<TValue>(key, value);
}

return item;
}
}

0 comments on commit 9003d0f

Please sign in to comment.