Understanding Redis Cluster Hash Slots: Concepts, Calculation, Allocation, and Dynamic Scaling
This article explains Redis cluster hash slots, how they partition data across 16,384 slots, the CRC16-based slot calculation, slot allocation to nodes, and demonstrates dynamic scaling operations such as adding, reshaping, and removing nodes with practical command‑line examples.
Redis cluster uses 16,384 hash slots to shard data across nodes, ensuring even distribution and supporting dynamic scaling.
Each key's CRC16 hash modulo 16,384 determines its slot; slots are assigned to nodes, each node managing a specific range.
Hash slots enable data partitioning, dynamic expansion/reduction, fault tolerance, and easier management.
Example allocation: Node A slots 0‑5500, Node B slots 5501‑11000, Node C slots 11001‑16383.
Commands to view slots, set keys, and observe redirection:
127.0.0.1:7001> set hello world
-> Redirected to slot [866] located at 127.0.0.1:7000
OKDynamic scaling: add a new node (port 7006) with redis-cli --cluster add-node 127.0.0.1:7006 127.0.0.1:7000 -a 123456 , then reshard slots using redis-cli --cluster reshard 127.0.0.1:7000 -a 123456 (move 300 slots to node 7006).
After resharding, verify slot distribution with cluster nodes . To shrink, move slots back and delete the node with redis-cli --cluster del-node 127.0.0.1:7006 624060ec59626a594ecffdb2f98e7d11a969d78d -a 123456 .
The article concludes that mastering hash slots is essential for Redis cluster operation and interview preparation.
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.