Redis Cluster: horizontal sharding and how data is distributed
hash slot concept, 16384 slots, CRC16 key hashing, node assignment, CLUSTER INFO, hash tags, MOVED redirect, ASK redirect, minimum 3 primary nodes
Redis Cluster for horizontal scale
Redis Cluster shards data across multiple nodes. Each key is assigned to one of 16,384 hash slots using CRC16. Each node owns a range of slots.
Creating a cluster
# redis.conf on each node
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
# Create cluster with 3 primaries + 3 replicas
redis-cli --cluster create \
127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 \
127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 \
--cluster-replicas 1Key routing
When you write a key, the client computes CRC16(key) % 16384 to find the slot, then sends the command to the owning node. If you hit the wrong node, Redis replies with MOVED {user:42}:profile and {user:42}:settings both hash on user:42, landing on the same node.
Multi-key operations
Multi-key commands like MSET only work if all keys share the same hash slot. Use hash tags to guarantee colocation when you need cross-key atomicity in a cluster.
