繁体   English   中英

StackExchange Redis - Net Framework - RedisConnectionException - 无法访问服务 HashSlot

[英]StackExchange Redis - Net Framework - RedisConnectionException - Serving HashSlot Is Not Reachable

基本上是使用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 散列槽范围内散列的键存储成功。

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

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

我的情况是我尝试从另一台机器连接到集群。 我通过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 后,问题已解决。

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

var options = ConfigurationOptions.Parse(host+":"+port);
options.ConnectTimeout = 60000; //60secs

ConnectionMultiplexer
.Connect(options)
.GetDatabase()
.StreamAdd(KeyName, "key", "value", flags: CommandFlags.DemandMaster);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM