Reputation: 125
I have a problem writing to a redis cluster.
Having this as configuration:
static readonly IEnumerable<EndPoint> Endpoints = new[]
{
EndPointCollection.TryParse("10.5.2.146:7000"),
EndPointCollection.TryParse("10.5.2.146:7001"),
EndPointCollection.TryParse("10.5.2.146:7002"),
};
public static ConnectionMultiplexer Build()
{
var opt = new ConfigurationOptions { AllowAdmin = true };
foreach (var endpoint in Endpoints)
opt.EndPoints.Add(endpoint);
Redis = ConnectionMultiplexer.Connect(opt);
FlushAllDatabases();
return Redis;
}
and using it like this:
var redis = RedisConfig.Build();
redis.GetDatabase().StringSet("foo", "bar");
redis.GetDatabase().StringGet("foo");
returns this exception:
StackExchange.Redis.RedisServerException: 'Endpoint 127.0.0.1:7002 serving hashslot 12182 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=1,Free=999,Min=4,Max=1000), WORKER: (Busy=0,Free=2047,Min=4,Max=2047), Local-CPU: n/a'
I think the problem is that: var endpoints = redis.GetEndPoints();
returns both configured endpoints with public IP and cluster-discovered endpoints (see image of inspected variable) with local IP, and then the node with private IP is used to retrieve the hashslot.
Is there anything else I should set up in the configuration or anything wrong using the client?
Currently used configuration, each node has it's folder .\700X
with it's own conf file and log:
redis.conf (for first node)
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
logfile 7000.log
protected-mode no
bind 0.0.0.0
nodes.conf
0c213c727e90710bbd94d5094da2c6749872f74f 127.0.0.1:7001 master - 0 1494253090995 2 connected 5461-10922
2e6d24ccec03d1ca674b936eac0e48dc6a97c405 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5460
7467c908c390bb6db202836fdff2966e4f100858 127.0.0.1:7007 slave bdd5c046e2a05b289ef0aba47a9987988defc799 0 1494253090889 8 connected
bbb2d02845e57622b5e95574ab843d9cefd0b28a 127.0.0.1:7006 slave 0c213c727e90710bbd94d5094da2c6749872f74f 0 1494253090890 7 connected
bdd5c046e2a05b289ef0aba47a9987988defc799 127.0.0.1:7002 master - 0 1494253092195 3 connected 10923-16383
c39aa6ff1e9823a169b758fc5aed2f5e811a971a 127.0.0.1:7008 slave bdd5c046e2a05b289ef0aba47a9987988defc799 0 1494253091700 9 connected
673d0af38625ae962f6ed7f527cc5162a08d7f21 127.0.0.1:7003 slave 2e6d24ccec03d1ca674b936eac0e48dc6a97c405 0 1494253091191 4 connected
ed1e5ba7a0a569e2d4b8542bf8a8353d33e81384 127.0.0.1:7004 slave 2e6d24ccec03d1ca674b936eac0e48dc6a97c405 0 1494253090889 5 connected
a4d29951bcf70593d14fbee5438608c88c971922 127.0.0.1:7005 slave 0c213c727e90710bbd94d5094da2c6749872f74f 0 1494253091722 6 connected
vars currentEpoch 9 lastVoteEpoch 0
Upvotes: 3
Views: 2706
Reputation: 860
I had the same issue as well. There is also another way to ensure the ip is announced the way you need, in the config file there is a part for NAT addesses. The only issue with my answer, as well as the previous answer is you need to know the correct ip address, and it should be static ...
cluster-announce-ip
Upvotes: 2
Reputation: 3305
I tested the scenario with jedis, and this problem also exists: public and private IP can both exist when connecting to redis cluster.
To solve it, use public ip when setting up the cluster, and make sure that the public ips are in every node.conf config. If "127.0.0.1" is written in node.conf, and connect to "10.5.2.146:7000", these two ips will both exist.
And a quick way to fix this at the situation: cluster meet 3 public ips in redis-cli, like
cluster meet 10.5.2.146 7000
cluster meet 10.5.2.146 7001
cluster meet 10.5.2.146 7002
Upvotes: 2