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?

2
  • Are you referring to the StackExchange.Redis library? Commented Oct 14, 2015 at 14:53
  • Yes - this Commented Oct 14, 2015 at 15:01

1 Answer 1

5
+300

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.