Search code examples
redisspring-data-redisnode-redisredis-cluster

How to create redis custom master slave node with redis-cli cluster create


This is my first time to implement redis cluster. Based on redis-cluster tutorial i need at least 3 masters and 3 slaves, currently i have 4 servers

192.168.0.10 -> 1111 as master, 1122 as slave
192.168.0.20 -> 1111 as master, 1122 as slave
192.168.0.30 -> 1111 as master, 1122 as slave
192.168.0.40 -> 1111 as slave, 1122 as slave

Then i want to use the first three for master and slave, and the last one (192.168.0.40) for slave only.

How to do that? since in the command that i found in the tutorial i supposed to write it as

./redis-cli --cluster create 192.168.0.10:1111 192.168.0.20:1111 192.168.0.30:1111 
192.168.0.10:1122 192.168.0.20:1122 192.168.0.30:1122 
--cluster-replicas 1 

Then how to add the fourth one? is something like this?

./redis-cli --cluster create 192.168.0.10:1111 192.168.0.20:1111 192.168.0.30:1111 
192.168.0.10:1122 192.168.0.20:1122 192.168.0.30:1122 
192.168.0.40:1111 192.168.0.40:1122 
--cluster-replicas 1 

Thanks


Solution

  • There is documentation on adding a new node as a replica

    There you can use the add-node command with the cluster-slave option. The first argument is the address for the new node and the second the address of a random node existing in the cluster.

    redis-cli --cluster add-node 192.168.0.40:1111 192.168.0.10:1111 --cluster-slave
    redis-cli --cluster add-node 192.168.0.40:1112 192.168.0.10:1111 --cluster-slave