How to Reshard Slots in a Redis Cluster
This article explains the process of moving hash slots between nodes in a Redis cluster using the redis-cli --cluster reshard command, detailing the required parameters, interactive steps, and verification of successful slot migration.
In the IT industry, frequent job changes are common to stay competitive, and similarly, data in a Redis cluster can "jump" between slots to balance load or improve performance.
Redis clusters consist of 16,384 hash slots, and keys are distributed across these slots. When needed, specific slots can be migrated from one node to another.
After creating a cluster, you can view the current slot allocation using the redis-cli --cluster slots 127.0.0.1:7000 command, which lists each node, its address, and the range of slots it owns.
To start migrating data, run the reshard command:
redis-cli --cluster reshard 127.0.0.1:7000 -a 123456
During the interactive prompt, you will specify:
The number of hash slots to move.
The destination node ID.
The source node IDs (or use "all" for all source nodes).
An example interaction might look like this:
How many slots do you want to move (from 1 to 16384)? 3 What is the receiving node ID? ce38cdcff0670229e12c9b7faedced0b0d104b91 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: 6d522d4d210bbaa78be3d44062df8db473d81237 Source node #2: done Ready to move 3 slots. Source nodes: M: 6d522d4d210bbaa78be3d44062df8db473d81237 127.0.0.1:7000 slots:[0-5460] (5461 slots) master Destination node: M: ce38cdcff0670229e12c9b7faedced0b0d104b91 127.0.0.1:7001 slots:[5461-10922] (5462 slots) master Resharding plan: Moving slot 0 from 6d522d4d210bbaa78be3d44062df8db473d81237 Moving slot 1 from 6d522d4d210bbaa78be3d44062df8db473d81237 Moving slot 2 from 6d522d4d210bbaa78be3d44062df8db473d81237 Do you want to proceed with the proposed reshard plan (yes/no)? yes Moving slot 0 from 127.0.0.1:7000 to 127.0.0.1:7001: Moving slot 1 from 127.0.0.1:7000 to 127.0.0.1:7001: Moving slot 2 from 127.0.0.1:7000 to 127.0.0.1:7001:
After the migration, you can verify the new slot distribution with the check command:
[root@localhost bin]# redis-cli --cluster check 127.0.0.1:7000 -a 123456 ... (output showing slots now assigned to the target node) ... All 16384 slots covered.
The article concludes that while the automated resharding process handles most cases, a manual approach using setslot , getkeyinslot , and migrate commands also exists but is more complex and not covered here.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.