redis - 将 StackExchange.Redis 与 ElastiCache 结合使用

标签 redis stackexchange.redis amazon-elasticache

我计划使用 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;

当关闭/崩溃不同的服务器时,我收到了三种类型的异常:RedisServerExceptionRedisConnectionExceptionTimeoutException。并在服务器/集群再次启动并运行后停止接收异常。

关于redis - 将 StackExchange.Redis 与 ElastiCache 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32057289/

相关文章:

ruby - 将内存缓存客户端与 ruby​​ 一起使用

redis - redis scan 是否会扫描开始扫描操作后插入的数据?

amazon-web-services - AWS + Celery + ElastiCache(Redis 集群)错误 : CROSSSLOT Keys in request don't hash to the same slot

c# - StackExchange.Redis 是否在内存缓存中使用本地?

c# - 在 Redis 缓存对象中执行搜索

java - Spring 启动Redis : Distributed Caching of Objects from Backend Services for parallel consumer requests for the same Object

redis - 如何为Redis和他的哨兵指定密码?

database - 如果 Redis 不在您的应用程序服务器上运行,为什么还要使用它?

django - 如何将 Django-Timeline 连接到 Redis 后端?

c# - 如何在 Redis 中对 Key 的值部分进行范围查询搜索?