The basic building of a Redis cluster is described in Redis 3 cluster (i). This section focuses on the operation of the Redis cluster.
Add master node to cluster
REDIS-TRIB.RB Add-node 127.0.0.1:7006 127.0.0.1:7000
Node: The new node does not contain any data because it does not contain any slots. The newly added add-on is a master node that will not be selected when the cluster needs to upgrade a slave node to a new master node.
redis-trib.rb reshard 127.0.0.1:7000# follow the prompts to select the number of slots to migrate (PS: select here) how many slots do you want to move (from 1 to 16384) 500# Select the Node-idwhat to accept these slots is the receiving node id? f51e26b5d5ff74f85341f06f28f125b7254e61bf# Select slot Source: # All means re-allocating from all master, #或者数据要提取slot的master节点id, and end with done Please enter all the source node IDs. Type ' All ' to use all the nodes as source nodes for the hash slots. type ' Done ' once you entered all the source nodes ids.source node # 1:3375be2ccc321932e8853234ffa87ee9fde973ffsource node #2:d one# Print the moved slot, enter Yes to begin moving the slot and the corresponding data. #Do you want to proceed with the proposed reshard plan (yes/no) ? yes# End
REDIS-CLI-C-P 7000cluster nodes
You can see that 7006 of the returned cluster information has 0-999 hash slots.
Adding slave nodes to the cluster
REDIS-TRIB.RB Add-node 127.0.0.1:7007 127.0.0.1:7000
REDIS-CLI-C-P 7007# parameter is idcluster replicate 2b9ebcbd627ff0fd7a7bbcc5332fb09e72788835 of master node
Delete a Slave node
#redis-trib del-node ip:port ' <node-id> ' redis-trib.rb del-node 127.0.0.1:7007 ' c7ee2fca17cb79fe3c9822ced1d4f6c5e169e378 '
Delete a master node
Before deleting the master node, first use Reshard to remove all of the master slots and then delete the current node (currently only the slots of the deleted master are migrated to one node)
redis-trib.rb reshard 127.0.0.1:7006# follow the prompts to select the number of slots to migrate (PS: select here) how many slots do you want to move (from 1 to 16384) 500# Select the Node-idwhat to accept these slots is the receiving node id? f51e26b5d5ff74f85341f06f28f125b7254e61bf# Select slot Source: # All means re-allocating from all master, #或者数据要提取slot的master节点id, and end with done Please enter all the source node IDs. Type ' All ' to use all the nodes as source nodes for the hash slots. type ' Done ' once you entered all the source nodes ids.source node # 1:3375be2ccc321932e8853234ffa87ee9fde973ffsource node #2:d one# Print the moved slot, enter Yes to begin moving the slot and the corresponding data. #Do you want to proceed with the proposed reshard plan (yes/no) ? yes# End # Delete empty master node redis-trib.rb del-node 127.0.0.1:7006 ' c7ee2fca17cb79fe3c9822ced1d4f6c5e169e378 '
Redis 3 cluster (ii)