10

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?

thepirat000
  • 12,362
  • 4
  • 46
  • 72
nirw
  • 225
  • 2
  • 10

1 Answers1

5

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.

thepirat000
  • 12,362
  • 4
  • 46
  • 72
  • In case the request tries a node that is down, will it try sending the request to the other known nodes, or just throw an exception? – nirw Oct 14 '15 at 19:28
  • I think it will depend on the moment the server goes down. You will probably get a MOVED RedisServerException if the cluster is recovering, or CLUSTERDOWN is cluster was not able to recover. In neither case you need to re-create the multiplexer. – thepirat000 Oct 14 '15 at 20:22