将 StackExchange.Redis 与 ElastiCache 结合使用

using StackExchange.Redis with ElastiCache

我打算使用 ConnectionMultiplexer.Connect("server1:6379,server2:6379") 语法,ElastiCache 复制组中每个节点的 addressses:port 数字组合(以 AWS 术语表示)。

库会处理 dead/unresponsive 个节点,自动将命令传递给活动节点吗?
库会自动发现失败的节点现在再次可用/添加到复制组的新节点吗?

我不熟悉 Elasticache,但是 StackExchange.Redis ConnectionMultiplexer 如果连接断开,它会在后台自动重试,它会发现恢复的节点。

当然,在访问数据库时出现故障时会出现异常,但如果正确处理错误,则不需要重新创建 ConnectionMultiplexer

我使用以下代码在集群模式和独立模式下对此进行了测试:

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;

我在关闭 down/crashing 不同的服务器时收到了三种类型的异常:RedisServerExceptionRedisConnectionExceptionTimeoutException。并在 server/cluster 启动并再次 运行 后停止接收异常。