Redis cluster master slave - not able to add key
Asked Answered
H

5

12

I have setup up Redis master slave configuration having one master (6379 port) and 3 slaves (6380,6381,6382) running in the same machine. Looks like cluster is setup properly as I can see the following output on running info command:

# Replication
role:master
connected_slaves:3
slave0:ip=127.0.0.1,port=6380,state=online,offset=29,lag=1
slave1:ip=127.0.0.1,port=6381,state=online,offset=29,lag=1
slave2:ip=127.0.0.1,port=6382,state=online,offset=29,lag=1
master_repl_offset:43
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:42

But wherever I try to add new key in master, I get the following error:

(error) CLUSTERDOWN Hash slot not served

Using redis-3.0.7 in Mac OS X Yosemite.

Has answered 21/3, 2016 at 7:15 Comment(2)
what do you get when you run redis-cli -p 6379 cluster nodes ? , it seams that one of the hash slots is not assigned, which makes the whole cluster go down.Conducive
Have you ever solved that?Bresnahan
E
13

To fix slots issue while insertion:

redis-cli --cluster fix localhost:6379
Expansionism answered 21/1, 2022 at 7:18 Comment(0)
C
12

I had the same issue, turned out I forgot to run the create cluster:

cd /path/to/utils/create-cluster 
./create-cluster create

http://redis.io/topics/cluster-tutorial#creating-a-redis-cluster-using-the-create-cluster-script

Communistic answered 16/8, 2016 at 10:6 Comment(0)
A
1

You can use ruby script buddled with redis for creating clusters as mentioned below :

/usr/local/redis-3.2.11/src/redis-trib.rb create --replicas  1 192.168.142.128:7001  192.168.142.128:7002 192.168.142.128:7003  192.168.142.128:7004  192.168.142.128:7005 192.168.142.128:7006
Aureole answered 10/10, 2017 at 15:3 Comment(0)
O
1

There is a hash slot not allotted to any master. Check the hash slots by looking at the column 9 in the output of following command (column 9 will be empty if no hash slots for that node):

redis-cli -h masterIP -p masterPORT CLUSTER NODES

The hash slots can be allotted by using the following command.

redis-cli -h masterIP -p masterPORT CLUSTER ADDSLOTS SLOTNNUMBER

But this has to be done for every slot number individually without missing. Use a bat script to include it in for loop. something like,

for /L %a in (0,1,5400) Do redis-cli -h 127.0.0.1 -p 7001  cluster addslots %a

Also, this command works before assigning slaves to master. After this ADDSLOTS step and completing the setup, the SET and GET worked fine. Remember to use -c along with redis-cli before SET to enable cluster support.

Orthogenic answered 9/11, 2021 at 17:33 Comment(0)
W
0

The issue comes when one or more Redis nodes gets corrupted and can no longer serve its configured hash slots.

You will have to bootstrap the cluster again to make sure the nodes agree on the hash slots to serve.

If the Redis nodes contain data or a key in the database 0, you will have to clear this data before rerunning the bootstrap.

Whimsicality answered 2/6, 2021 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.