This repository was archived by the owner on Nov 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 49
This repository was archived by the owner on Nov 16, 2022. It is now read-only.
Implement ForceReconnect #56
Copy link
Copy link
Open
Description
Hi @AliBazzi
We've seen some instances while running in Azure Redis when a Redis failover has caused the ConnectionMultiplexer to not retry the connection (instead requiring a restart of the service), this isn't a great situation!
To avoid this in other projects we use the ForceReconnect pattern from the Redis
https://gist.github.com/JonCole/925630df72be1351b21440625ff2671f#file-redis-bestpractices-stackexchange-redis-md from
https://docs.microsoft.com/en-gb/azure/azure-cache-for-redis/cache-best-practices
It does require changing the Get / Set to check and reconnect to something like:
public async Task<bool> AddAsync<T>(string key, T value, TimeSpan expiresIn)
{
try
{
try
{
return await _cacheClient.AddAsync(key, value, expiresIn);
}
catch (RedisConnectionException)
{
RedisConnection.ForceReconnect();
}
catch (SocketException)
{
RedisConnection.ForceReconnect();
}
catch (WebSocketException)
{
RedisConnection.ForceReconnect();
}
}
catch (ObjectDisposedException)
{
//ForceReconnect can potentially throw ObjectDisposedException, nothing we can do, hopefully cache back on next call
return false;
}
return false;
}
Let me know if you'd consider adding this, or if a PR would be accepted.
thanks
wallism
Metadata
Metadata
Assignees
Labels
No labels