I plan to use the ConnectionMultiplexer.Connect("server1:6379,server2:6379")
syntax, with the addressses:port number combination of each of the node in an ElastiCache replication group (in AWS terms).
Will the library handle dead/unresponsive nodes, automatically passing commands to active nodes?
Will the library automatically discover a node that failed is now available again / new nodes that are added to the replication group?
I'm not familiar with Elasticache, but the StackExchange.Redis ConnectionMultiplexer
will automatically retry in the background if the connection is dropped, and it will discover recovered nodes.
Of course, upon failures you will get exceptions when accessing the database, but if you treat the errors correctly you'll not need to re-create the ConnectionMultiplexer
.
I used the following code to test this in cluster-mode and standalone-mode:
var mul = ConnectionMultiplexer.Connect("192.168.15.15:7000,192.168.15.15:7001,...,connectRetry=10,syncTimeout=5000,abortConnect=false,keepAlive=10,allowAdmin=true");
RETRY:
Thread.Sleep(1000);
var k = Guid.NewGuid().ToString();
var v = Guid.NewGuid().ToString();
try
{
var db = mul.GetDatabase();
db.StringSet(k, v);
if (db.StringGet(k).ToString() != v)
{
throw new OperationCanceledException("ABORT");
}
}
catch(RedisServerException ex)
{
Console.WriteLine("Redis Server Exception {0}", ex.Message);
goto RETRY;
}
catch(RedisConnectionException ex)
{
Console.WriteLine("Redis Connection Exception {0}", ex.Message);
goto RETRY;
}
catch(TimeoutException ex)
{
Console.WriteLine("Timeout Exception {0}", ex.Message);
goto RETRY;
}
Console.WriteLine("OK");
goto RETRY;
I've received three types of exceptions when shutting down/crashing the different servers: RedisServerException
, RedisConnectionException
and TimeoutException
. And stopped receiving exceptions once the server/cluster is up and running again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With