【问题标题】:StackExchange Redis - Net Framework - RedisConnectionException - Serving HashSlot Is Not ReachableStackExchange Redis - 网络框架 - RedisConnectionException - 服务 HashSlot 不可达
【发布时间】:2020-03-31 14:59:32
【问题描述】:

基本上是使用 StackExchangeRedis 客户端连接到具有 3 个节点的 Redis 集群。

我的配置如下:

            config.EndPoints.Add(IPAddress.Parse("Node1_IP"), port);
            config.EndPoints.Add(IPAddress.Parse("Node2_IP"), port);
            config.EndPoints.Add(IPAddress.Parse("Node3_IP"), port);

            config.Password = "password";

            config.DefaultDatabase = 0;

            config.ConnectTimeout = ConfigurationOptionsConnectTimeout;
            config.AsyncTimeout = ConfigurationOptionsConnectTimeout;

            config.ConnectRetry = InitialConnectRetries;
            config.ReconnectRetryPolicy = new ExponentialRetry(DeltaBackOffMilliseconds);

            config.AbortOnConnectFail = false;

Node1 HashSlot 范围是 0-8191

Node2 HashSlot 范围是 8192-16383

Node3 没有 HashSlot 范围,我猜它就像一个奴隶。

错误

StackExchange.Redis.RedisConnectionException: Endpoint Node1_IP:Port serving hashslot 14371 is
 not reachable at this point of time. Please check connectTimeout value. If it is low, try increasing it
 to give the ConnectionMultiplexer a chance to recover from the network disconnect. IOCP: 
(Busy=0,Free=1000,Min=6,Max=1000), WORKER: (Busy=0,Free=8191,Min=6,Max=8191), Local-CPU: n/a

场景: 试图在数据库中存储一些键值。

当我的密钥在属于 Node2 哈希槽范围的哈希槽中进行哈希处理(基于 Redis 哈希函数)时,会发生上述错误。 在节点 1 哈希槽范围内进行哈希处理的键存储成功。

IF 我重新排列配置中的端点,首先添加Node2_IP,然后添加Node1_IP,然后可以成功存储在Node2哈希槽中散列的键,但在散列槽范围内散列的键Node1 分别产生相同的错误。

【问题讨论】:

    标签: c# asp.net stackexchange.redis


    【解决方案1】:

    我遇到了另一个问题,但我的错误信息是一样的。也许这对您(或其他人)有帮助。

    我的场景是我试图从另一台机器连接到集群。我通过https://redis.io/topics/cluster-tutorial(即redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1)提供的示例设置集群。

    在我的代码中,我只提供了一个主节点(在本例中为 7000 个)。 StackExchangeRedis 显然会自动发现其他节点。由于我通过上面的命令设置它,它试图连接到 127.0.0.1:7001,但它显然不能。 编辑 cluster create 命令使其使用服务器的公共 IP 地址而不是 127.0.0.1 后,问题得到解决。

    【讨论】:

      【解决方案2】:

      在增加连接超时并设置 CommandFlags.DemandMaster 后,我也不一致地遇到了这个问题(仅在写入操作时使用)

      var options = ConfigurationOptions.Parse(host+":"+port);
      options.ConnectTimeout = 60000; //60secs
      
      ConnectionMultiplexer
      .Connect(options)
      .GetDatabase()
      .StreamAdd(KeyName, "key", "value", flags: CommandFlags.DemandMaster);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-01
        • 2010-10-21
        • 2012-08-14
        • 1970-01-01
        • 1970-01-01
        • 2010-11-03
        • 2012-04-24
        • 2018-08-16
        相关资源
        最近更新 更多