Redis cluster architecture details - common commands of redis cluster

5.8. Cluster common commands

5.8.1. Cluster restart and deletion

1. Close a node of the cluster

Close a node of the cluster, such as the instance with port number 7001:

redis-cli -a cyclone -c -h -p 7001 shutdown

The implementation effect is as follows:

After shutdown, use the following command to restart

redis-server /etc/redis/redis-cluster-7001/7001.conf

The command can restart the instance and automatically add it to the cluster after startup.

2. Cluster shutdown

Close the redis instance process one by one
Find redis instance process number

    ps -ef | grep redis

Close the redis process. Use kill -9 ${process number}. If you need to close multiple processes, separate the process numbers with spaces

kill -9 3535 3540 3545 3550 3555 24822

You can also execute the following command to shut down the redis process
pkill -9 redis

3. Restart the redis cluster

There are two ways to restart a redis cluster: keep the original data and discard the original data.

(1) Keep the original data:
Close the redis instances one by one, and then start them one by one.

(2) Discard the original data:

Close the instance, clear all the contents of the data storage directory in the instance, start the instance one by one, and execute the create command of the cluster on any instance, which is essentially to create a new cluster

Empty data storage directory contents:

   rm -rf /etc/redis/redis-cluster-7001/data/*
   rm -rf /etc/redis/redis-cluster-7002/data/*
   rm -rf /etc/redis/redis-cluster-7003/data/*
   rm -rf/etc/redis/redis-cluster-7004/data/*
   rm -rf /etc/redis/redis-cluster-7005/data/*
   rm -rf /etc/redis/redis-cluster-7006/data/*

Start instance:

  redis-server /etc/redis/redis-cluster-7001/7001.conf
  redis-server /etc/redis/redis-cluster-7002/7002.conf
  redis-server /etc/redis/redis-cluster-7003/7003.conf
  redis-server /etc/redis/redis-cluster-7004/7004.conf
  redis-server /etc/redis/redis-cluster-7005/7005.conf
  redis-server /etc/redis/redis-cluster-7006/7006.conf

Execute the cluster creation command:

redis-cli --cluster create --cluster-replicas 1

5.8.2.create create cluster

  • create
  • – replicas - optional parameter. Replicas indicates that each master needs several slave s.

The create command can select the replicas parameter, which indicates that several slave s are needed.

5.8.3. View cluster

CLUSTER INFO print cluster information

CLUSTER NODES lists all nodes currently known to the cluster and information about those nodes.

5.8.4. Node command

1. Add the nodes specified by ip and port to the cluster

CLUSTER MEET <ip> <port>

2. Remove the node specified by node [ID] from the cluster


3. Set the current node to the slave node of the node specified by the node ID


4. Save the configuration file of the node to the hard disk


5.8.5. slot command

1. assign one or more slot s to the current node

CLUSTER ADDSLOTS <slot> [slot ...]

2. Remove the assignment of one or more slots to the current node

CLUSTER DELSLOTS <slot> [slot ...]

3. Remove all slots assigned to the current node and make the current node a node without any slots assigned


4. Assign the slot slot to the node specified by node [ID]. If the slot is already assigned to another node, let the other node delete the slot > before assigning it

CLUSTER SETSLOT <slot> NODE <node_id>

5. Migrate the slot slot of this node to the node specified by node ID


6. Import slot slot from the node specified by node ID to this node


7. Cancel import ing or migrating slot


5.8.6. key command

1. Which slot should the calculation key be placed in


2. Returns the number of key value pairs currently contained in slot


3. Return the keys in count slot slots

147 original articles published, 22 praised, 110000 visitors+
Private letter follow

Tags: Redis

Posted on Wed, 11 Mar 2020 04:34:26 -0400 by mrtechguy