Manual Slot Migration in Redis Cluster: Step-by-Step Guide
This article explains how to manually migrate a hash slot in a Redis cluster by checking cluster status, setting importing and migrating slots, retrieving keys, using the MIGRATE command, and updating slot assignments across nodes, with detailed command examples and explanations.
Redis clusters can dynamically adjust hash slots at runtime, analogous to changing a tire on a moving airplane.
Hash slots migration essentially moves a set of keys; re-sharding transfers keys from one instance to another, and migrating a slot moves all keys within that slot.
The previous article introduced the reshard command for data migration; this article covers a more manual method with additional steps and commands.
First, create the cluster and set a key hello with value world , then obtain its slot (866):
127.0.0.1:7000> set hello world
OK
127.0.0.1:7000> cluster keyslot hello
(integer) 866Next, verify cluster health using cluster check :
[root@localhost bin]# redis-cli --cluster check 127.0.0.1:7000 -a 123456
... (output showing 16384 slots covered) ...Since the cluster is healthy, proceed to set the target node (port 7002) to importing state for slot 866:
127.0.0.1:7002> cluster setslot 866 importing 80c344093fefd4c444c71af6e771b25035187da
OKThen set the source node (port 7000) to migrating state for the same slot:
127.0.0.1:7000> cluster setslot 866 migrating c272f85a0ae58bc7c02b90ac16b73449c2e559ae
OKRetrieve keys in the slot (requesting up to 3 keys, only hello exists):
127.0.0.1:7000> cluster getkeysinslot 866 3
1) "hello"Migrate the key to the target node using migrate (specifying IP, port, key name, DB 0, timeout 5000, and authentication):
127.0.0.1:7000> migrate 127.0.0.1 7002 hello 0 5000 auth 123456
OKFinally, update slot ownership on all master nodes to reflect the new assignment:
127.0.0.1:7000> cluster setslot 866 node 80c344093fefd4c444c71af6e771b25035187da
OK
127.0.0.1:7000> cluster setslot 866 node fc93befbe33c74b0a7978eba595429744c5a77fd
OK
127.0.0.1:7000> cluster setslot 866 node c272f85a0ae58bc7c02b90ac16b73449c2e559ae
OKChecking the cluster nodes confirms that slot 866 now resides on node 7002, while node 7000 retains slots 0‑865 and 867‑5460. If the allocation fails, the cluster fix command can be used.
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.