A Redis cluster divides the keyspace into 16384 slots. Each master node is responsible for a subset of these slots. When you add a new node, it doesn't initially own any slots. Resharding moves slots from existing nodes to the new node, balancing the data and workload.
-
Connect to the Cluster using redis-cli --cluster
:
To perform the resharding operation, you'll use the redis-cli --cluster reshard
command. This command provides an interactive way to redistribute slots across the cluster.
Open your terminal and execute the following command:
redis-cli --cluster reshard 127.0.0.1:7000
This command connects to the Redis cluster through the node at 127.0.0.1:7000
and starts the resharding process.
-
Specify the Number of Slots to Move:
The redis-cli
tool will prompt you to enter the number of slots you want to move. For this example, let's move 101 slots to the new node.
How many slots do you want to move? (default: all)
Enter 101
and press Enter.
-
Enter the Target Node ID:
Next, the tool will ask you to enter the node ID of the target node, which is the new node you added in the previous step (port 7006). To find the node ID, you can use the CLUSTER NODES
command as shown in the previous steps, or you can use the following command to get the node ID directly:
redis-cli -h 127.0.0.1 -p 7006 cluster nodes | grep myself | awk '{print $1}'
Copy the node ID from the output. The redis-cli
tool will prompt you:
What is the receiving node ID?
Paste the node ID and press Enter.
-
Specify the Source Nodes:
The tool will ask you to specify the source nodes from which to take the slots. You can enter all
to redistribute slots from all existing master nodes.
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' to stop entering IDs.
Enter all
and press Enter.
-
Confirm the Resharding Plan:
The redis-cli
tool will display the resharding plan and ask you to confirm.
Do you want to proceed with the reshard plan? (type 'yes' to accept):
Type yes
and press Enter to start the resharding process.
-
Wait for Resharding to Complete:
The redis-cli
tool will now move the slots from the source nodes to the target node. This process may take some time, depending on the amount of data in the cluster. You will see progress messages as the slots are being moved.
-
Exit redis-cli
: