August 20, 2021

redis cluster create add forget

!!! CREATE REDIS CLUSTER

[email protected]:/data# redis-cli -h 192.168.116.133 -p 7001 --cluster create 192.168.116.133:7001 192.168.116.134:7002 192.168.116.135:7003 192.168.116.136:7004 192.168.116.137:7005 192.168.116.141:7006 --cluster-replicas 1

>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.116.137:7005 to 192.168.116.133:7001
Adding replica 192.168.116.141:7006 to 192.168.116.134:7002
Adding replica 192.168.116.136:7004 to 192.168.116.135:7003
M: 793744f275a0c967b8aeea0f5ae4c1f8978c089a 192.168.116.133:7001
   slots:[0-5460] (5461 slots) master
M: 7cec1aceec39b4afd7b17a3650e8f224b5ab4903 192.168.116.134:7002
   slots:[5461-10922] (5462 slots) master
M: c2499885dd44975d24902d5886cc5a17056620df 192.168.116.135:7003
   slots:[10923-16383] (5461 slots) master
S: eb5b691cd9ab7d7ebb0fe4babbc05f95cced662b 192.168.116.136:7004
   replicates c2499885dd44975d24902d5886cc5a17056620df
S: d504e959b57165aca85e997fac483dc6660e7529 192.168.116.137:7005
   replicates 793744f275a0c967b8aeea0f5ae4c1f8978c089a
S: 7b12a83652bb2e7421685db047e90ea0a4746d70 192.168.116.141:7006
   replicates 7cec1aceec39b4afd7b17a3650e8f224b5ab4903
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node 192.168.116.133:7001)
M: 793744f275a0c967b8aeea0f5ae4c1f8978c089a 192.168.116.133:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: c2499885dd44975d24902d5886cc5a17056620df 192.168.116.135:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: eb5b691cd9ab7d7ebb0fe4babbc05f95cced662b 192.168.116.136:7004
   slots: (0 slots) slave
   replicates c2499885dd44975d24902d5886cc5a17056620df
S: d504e959b57165aca85e997fac483dc6660e7529 192.168.116.137:7005
   slots: (0 slots) slave
   replicates 793744f275a0c967b8aeea0f5ae4c1f8978c089a
S: 7b12a83652bb2e7421685db047e90ea0a4746d70 192.168.116.141:7006
   slots: (0 slots) slave
   replicates 7cec1aceec39b4afd7b17a3650e8f224b5ab4903
M: 7cec1aceec39b4afd7b17a3650e8f224b5ab4903 192.168.116.134:7002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

[email protected]:/data# redis-cli -c -p 7001
127.0.0.1:7001> cluster nodes
c2499885dd44975d24902d5886cc5a17056620df 192.168.116.135:[email protected] master - 0 1629442429000 3 connected 10923-16383
eb5b691cd9ab7d7ebb0fe4babbc05f95cced662b 192.168.116.136:[email protected] slave c2499885dd44975d24902d5886cc5a17056620df 0 1629442429367 3 connected
d504e959b57165aca85e997fac483dc6660e7529 192.168.116.137:[email protected] slave 793744f275a0c967b8aeea0f5ae4c1f8978c089a 0 1629442429882 1 connected
793744f275a0c967b8aeea0f5ae4c1f8978c089a 192.168.116.133:[email protected] myself,master - 0 1629442430000 1 connected 0-5460
7b12a83652bb2e7421685db047e90ea0a4746d70 192.168.116.141:[email protected] slave 7cec1aceec39b4afd7b17a3650e8f224b5ab4903 0 1629442430393 2 connected
7cec1aceec39b4afd7b17a3650e8f224b5ab4903 192.168.116.134:[email protected] master - 0 1629442429000 2 connected 5461-10922

!!! FORGET 7b12a83652bb2e7421685db047e90ea0a4746d70 fail node

### redis-cli cluster forget [fail node id]

127.0.0.1:7001> cluster nodes
c2499885dd44975d24902d5886cc5a17056620df 192.168.116.135:[email protected] master - 0 1629445955019 3 connected 10923-16383
eb5b691cd9ab7d7ebb0fe4babbc05f95cced662b 192.168.116.136:[email protected] slave c2499885dd44975d24902d5886cc5a17056620df 0 1629445954004 3 connected
d504e959b57165aca85e997fac483dc6660e7529 192.168.116.137:[email protected] slave 793744f275a0c967b8aeea0f5ae4c1f8978c089a 0 1629445953000 1 connected
793744f275a0c967b8aeea0f5ae4c1f8978c089a 192.168.116.133:[email protected] myself,master - 0 1629445954000 1 connected 0-5460
7b12a83652bb2e7421685db047e90ea0a4746d70 :[email protected] slave,fail,noaddr 7cec1aceec39b4afd7b17a3650e8f224b5ab4903 1629445922737 1629445920166 2 disconnected
7cec1aceec39b4afd7b17a3650e8f224b5ab4903 192.168.116.134:[email protected] master - 0 1629445953000 2 connected 5461-10922

127.0.0.1:7001> CLUSTER FORGET 7b12a83652bb2e7421685db047e90ea0a4746d70
OK
!!! ADD New Node join exist cluster

### redis-cli --cluster add-node  [new nodeip:port] [exist nodeip:port] {--cluster-slave | --cluster-master-id}

[email protected]:/data#  redis-cli -h 192.168.116.133 -p 7001 --cluster add-node 192.168.116.141:7006 192.168.116.134:7002 --cluster-slave

[email protected]:/data#  redis-cli -h 192.168.116.133 -p 7001 --cluster add-node 192.168.116.141:7006 192.168.116.134:7002 --cluster-slave
>>> Adding node 192.168.116.141:7006 to cluster 192.168.116.134:7002
>>> Performing Cluster Check (using node 192.168.116.134:7002)
M: 7cec1aceec39b4afd7b17a3650e8f224b5ab4903 192.168.116.134:7002
   slots:[5461-10922] (5462 slots) master
S: d504e959b57165aca85e997fac483dc6660e7529 192.168.116.137:7005
   slots: (0 slots) slave
   replicates 793744f275a0c967b8aeea0f5ae4c1f8978c089a
S: eb5b691cd9ab7d7ebb0fe4babbc05f95cced662b 192.168.116.136:7004
   slots: (0 slots) slave
   replicates c2499885dd44975d24902d5886cc5a17056620df
M: 793744f275a0c967b8aeea0f5ae4c1f8978c089a 192.168.116.133:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: c2499885dd44975d24902d5886cc5a17056620df 192.168.116.135:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Automatically selected master 192.168.116.134:7002
>>> Send CLUSTER MEET to node 192.168.116.141:7006 to make it join the cluster.
Waiting for the cluster to join
>>> Configure node as replica of 192.168.116.134:7002.
[OK] New node added correctly.

127.0.0.1:7001> cluster nodes
ea5ea0bbd7cf0cdb81aa55a4643f894021caa327 192.168.116.141:[email protected] slave 7cec1aceec39b4afd7b17a3650e8f224b5ab4903 0 1629448076638 2 connected
c2499885dd44975d24902d5886cc5a17056620df 192.168.116.135:[email protected] master - 0 1629448076531 3 connected 10923-16383
eb5b691cd9ab7d7ebb0fe4babbc05f95cced662b 192.168.116.136:[email protected] slave c2499885dd44975d24902d5886cc5a17056620df 0 1629448075609 3 connected
d504e959b57165aca85e997fac483dc6660e7529 192.168.116.137:[email protected] slave 793744f275a0c967b8aeea0f5ae4c1f8978c089a 0 1629448075098 1 connected
793744f275a0c967b8aeea0f5ae4c1f8978c089a 192.168.116.133:[email protected] myself,master - 0 1629448075000 1 connected 0-5460
7cec1aceec39b4afd7b17a3650e8f224b5ab4903 192.168.116.134:[email protected] master - 0 1629448076533 2 connected 5461-10922