Search code examples
rediscluster-computingredis-cluster

Cannot add values to Redis cluster - The cluster is down


I have 4 nodes, 3 are master and 1 of them is a slave. I am trying to add a simple string by set foo bar, but whenever i do it, i get this error:

(error) CLUSTERDOWN The cluster is down

Below is my cluster info

127.0.0.1:7000cluster info

cluster_state:fail

cluster_slots_assigned:11

cluster_slots_ok:11

cluster_slots_pfail:0

cluster_slots_fail:0

cluster_known_nodes:4

cluster_size:3

cluster_current_epoch:3

cluster_my_epoch:3

cluster_stats_messages_sent:9262

cluster_stats_messages_received:9160

I am using Redis-x64-3.0.503. please let me know how to solve this

Cluster Nodes:

87982f22cf8fb12c1247a74a2c26cdd1b84a3b88 192.168.2.32:7000 slave bc1c56ef4598fb4ef9d26c804c5fabd462415f71 1492000375488 1492000374508 3 connected

9527ba919a8dcfaeb33d25ef805e0f679276dc8d 192.168.2.35:7000 master - 1492000375488 1492000374508 2 connected 16380

ff999fd6cbe0e843d1a49f7bbac1cb759c3a2d47 192.168.2.33:7000 master - 1492000375488 1492000374508 0 connected 16381

bc1c56ef4598fb4ef9d26c804c5fabd462415f71 127.0.0.1:7000 myself,master - 0 0 3 connected 1-8 16383

Solution

  • Just to add up and simplify what @neuront said.

    Redis stores data in hash slots. For this to understand you need to know how Hasmaps or Hashtables work. For our reference here redis has a constant of 16384 slots to assign and distribute to all the masters servers.

    Now if we look at the node configuration you posted and refer it with redis documentation, you'll see the end numbers mean the slots assigned to the masters.

    In your case this is what it looks like

    ... slave  ... connected
    ... master ... connected 16380
    ... master ... connected 16381
    ... master ... connected 1-8 16380
    

    So all the machines are connected to form up the cluster but not all the hash slots are assigned to store the information. It should've been something like this

    ... slave  ... connected
    ... master ... connected 1-5461
    ... master ... connected 5462-10922
    ... master ... connected 10923-16384
    

    You see, now we are assigning the range of all the hash slots like the documentation says

    slot: A hash slot number or range. Starting from argument number 9, but there may be up to 16384 entries in total (limit never reached). This is the list of hash slots served by this node. If the entry is just a number, is parsed as such. If it is a range, it is in the form start-end, and means that the node is responsible for all the hash slots from start to end including the start and end values.

    For specifically in your case, when you store some data with a key foo, it must've been assigned to some other slot not registered in the cluster.

    Since you're in Windows, you'll have to manually setup the distribution. For that you'll have to do something like this (this is in Linux, translate to windows command)

    for slot in {0..5400}; do redis-cli -h master1 -p 6379 CLUSTER ADDSLOTS $slot; done;
    

    taken from this article

    Hope it helped.