The 16,384 hash slot model, CRC16 key hashing, hash tags for co-locating keys on the same slot, MOVED vs ASK redirections, multi-key command constraints in Cluster, and cluster-enabled client configuration.
A-9 — Redis Cluster: Hash Slots and Data Distribution
Who this module is for: Your Redis dataset has grown beyond what a single node can hold in RAM, or your write throughput exceeds what a single node can handle. Redis Cluster is the answer — but it introduces constraints around multi-key operations, key routing, and command support that you must understand before adopting it. This module covers the Cluster model end-to-end.
Why Cluster?
A single Redis node has two hard limits:
- RAM — the entire dataset must fit in one machine's memory. A 1TB dataset cannot fit on a 256GB node.
- Write throughput — all writes go through one single-threaded event loop. At some point, you hit the wall (~1M ops/sec on modern hardware).
Redis Cluster solves both by distributing data across multiple primary nodes, each responsible for a subset of the keyspace.
The Hash Slot Model
Redis Cluster partitions the keyspace into 16,384 hash slots (numbered 0–16383). Every key belongs to exactly one slot:
slot = CRC16(key) % 16384
Hash slots are assigned to primary nodes. A 3-node cluster might assign:
When a client issues GET user:1001, Redis computes CRC16("user:1001") % 16384 = 7638. Slot 7638 belongs to Node 2. The client sends the GET to Node 2.
MOVED and ASK Redirections
Cluster clients must track which node owns which slots. When a client sends a command to the wrong node, the node responds with a MOVED redirection:
The client updates its local slot-to-node map and resends the command to the correct node. A well-implemented Cluster client handles this automatically and transparently — application code does not see MOVED errors.
ASK redirections are similar but temporary — used during slot migration (when a slot is being moved from one node to another). ASK means "ask this specific node for this specific command, but do not update your slot map."
Hash Tags: Controlling Key Placement
Multi-key commands (MGET, MSET, pipelines, Lua scripts, transactions) require all keys to be on the same node. In Cluster mode, this means all keys must be in the same hash slot.
Hash tags force a specific portion of the key to be used for slot computation:
With hash tags, all keys for a specific user share the same slot — enabling multi-key operations:
Design rule: For related keys that must be accessed together, use hash tags from the start. Retrofitting hash tags requires migrating all existing keys.
Multi-Key Command Constraints
Commands that operate on multiple keys fail in Cluster if the keys span different slots:
Workarounds:
- Hash tags — co-locate related keys on the same slot
- Application-side batching — split multi-key operations by slot, execute per-node, merge results in the application
- Single-key alternatives — replace
MGETwith a pipeline ofGETcommands (each routed to the correct node automatically by the Cluster client)
Sign in to keep reading
The rest of this module is free — sign in with Google to unlock it and track your progress.
Sign in & RegisterDiscussion
0Join the discussion