5

I have created a cluster of 6 nodes using redis docker-compose (3 master and 3 slave) and also linked all of them. cluster info

cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:5
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:23
cluster_stats_messages_pong_sent:31
cluster_stats_messages_meet_sent:1
cluster_stats_messages_sent:55
cluster_stats_messages_ping_received:26
cluster_stats_messages_pong_received:24
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:55

cluster nodes

d794a9ab002f0c3cb699ce68a09310dd0fdb17de 192.168.65.3:32789@32783 slave c6c05515c3be01a1438b6d2aad823c0fa50b1743 0 1586629088989 5 connected
7d4fab850bcfac8754a559c5e9469698b7f182bc 192.168.65.3:32792@32787 master - 0 1586629087000 2 connected 5461-10922
c6c05515c3be01a1438b6d2aad823c0fa50b1743 192.168.65.3:32793@32788 master - 0 1586629089995 4 connected 10923-16383
229b9b4f919f79a1c24b7b849c42acb9e3378532 192.168.65.3:32790@32785 slave 9b649a67dc53084ed7416b20e8bab00289e636d2 0 1586629089000 6 connected
9b649a67dc53084ed7416b20e8bab00289e636d2 192.168.65.3:32791@32786 myself,master - 0 1586629086000 1 connected 0-5460

As shown above the cluster seems to be working but when I try to call the cluster instance in a java application using jedis by using the code

jedis = new JedisCluster(new HostAndPort("0.0.0.0", 32790));
jedis.set("events/city/rome", "32,15,223,828");

then I get the following error

Exception in thread "main" redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException: No more cluster attempts left.
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:86)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
    at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:25)
    at redis.clients.jedis.JedisCluster.set(JedisCluster.java:112)
    at sc.dev.algordf.ALGORDF.main(ALGORDF.java:53)

Please help me find out what could be the problem. Is it because I have not specified the right IP and port number when creating a jedis instance. Or is it something that I am missing.

Thanks.

1 Answers1

4

The problem is in Redis Cluster config!

Your app requests to one of the configured nodes. It receives the address of all Redis nodes, in your case is IP in the Docker network. As a result, you get a connection error.

To fix this, add the following parameter to each node in the cluster to update the "advertise" address

Example with node 192.168.83.101:7000:17000 (docker host is 192.168.83.101, command port is 7000, cluster bus port is 17000)

cluster-announce-ip 192.168.83.100
cluster-announce-port 7000
cluster-announce-bus-port 17000
Linh Vu
  • 66
  • 4