Basically am using StackExchangeRedis client to connect to a Redis Cluster with 3 Nodes.
My configuration is the following:
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 range is from 0-8191
Node2 HashSlot range is from 8192-16383
Node3 has no HashSlot range, it’s like a slave i guess.
Error:
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
Scenario:
Trying to store some key-value in the database.
The above error occurs when my key is hashed(based on Redis hash function) in a hash slot that belongs to Node2 hash slot range.
The keys that are hashed in Node 1 hash slot range are stored successfully.
IF I rearrange the endpoints in the configuration by adding Node2_IP firstly and Node1_IP secondly, then the keys that are hashed in Node2 hash slots can be stored successfully but the keys that are hashed in hash slot range of Node1 produce the same error respectively.
2
Answers
I had another problem but my error message was the same. Maybe this helps you (or somebody else).
My scenario was that I tried to connect to the cluster from another machine. I set up the cluster via the example provided by https://redis.io/topics/cluster-tutorial (i.e.
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
).In my code I only provided one of the master nodes (7000 in this case). StackExchangeRedis apparently auto discovers the other nodes. Since I set it up via the above command it tried to connect to 127.0.0.1:7001 which it obviously couldn’t.
After editing the cluster create command so it uses the public IP address of the server instead of 127.0.0.1, the problem was resolved.
I too faced this issue inconsistently, after increasing the connection timeout and setting the CommandFlags.DemandMaster (use this only if its a write operation)