我计划使用 ConnectionMultiplexer.Connect("server1:6379,server2:6379")
语法,以及 ElastiCache 复制组中每个节点的地址:端口号组合(以 AWS 术语表示)。
库会处理死节点/无响应节点,自动将命令传递给事件节点吗?
库是否会自动发现失败的节点现在再次可用/添加到复制组的新节点?
最佳答案
我不熟悉 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;
当关闭/崩溃不同的服务器时,我收到了三种类型的异常:RedisServerException
、RedisConnectionException
和 TimeoutException
。并在服务器/集群再次启动并运行后停止接收异常。
关于redis - 将 StackExchange.Redis 与 ElastiCache 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32057289/