-- A Redis Cluster automatically distributes keys
-- across multiple nodes based on hash slots
redis-cli -c -h node1 set user:123 'John'
Topics
40
Caching Patterns
Cluster Sharding & Hash Slots
Clustering
Connection Pooling & Client Libraries
Data Types
Distributed Locks with Redis
Expiration & Eviction
Geospatial Data in Redis
Hashes in Redis
HyperLogLog in Redis
Keyspace Notifications
Leaderboards with Sorted Sets
Lists in Redis
Lua Scripting
Persistence (RDB/AOF)
Pub/Sub
Rate Limiting with Redis
Redis Architecture & Installation
Redis as a Message Queue
Redis Backup & Disaster Recovery
Redis CLI & Basic Commands
Redis Memory Optimization
Redis Modules Overview
Redis Monitoring & Observability
Redis Performance Tuning & Benchmarking
Redis Replication
Redis Security & ACL
Redis Sentinel & High Availability
Redis vs Memcached
Redis with Docker & Kubernetes
RedisBloom (Probabilistic Data Structures)
RedisJSON
RedisSearch (Full Text Search)
RedisTimeSeries
Session Management with Redis
Sets & Sorted Sets in Redis
Streams
Strings & Bitmaps in Redis
TLS & Encryption in Redis
Transactions
Cluster Sharding & Hash Slots
7 questions found
Sharding splits your data across multiple Redis nodes instead of storing everything on a single server, letting you scale beyond the memory and processing limits of one machine by distributing both the data and the workload of serving requests across several nodes working together.
Real-world example
A large social media platform shards its user session data across many Redis nodes, since a single server could never hold enough memory to store session data for millions of active users at once.
Clustering;Redis Replication
Redis Cluster divides its entire key space into sixteen thousand three hundred and eighty four hash slots, and every key is assigned to exactly one of these slots based on a hash calculation, with each node in the cluster responsible for owning and serving a specific range of these slots.
-- Check which hash slot a key belongs to
redis-cli cluster keyslot user:123
Real-world example
A three node Redis Cluster might divide its sixteen thousand three hundred eighty four hash slots roughly evenly, with each node responsible for owning about five thousand four hundred slots and the keys that map to them.
Clustering;Cluster Sharding & Hash Slots
Redis Cluster applies a hashing algorithm called CRC16 to the key, then takes the result modulo sixteen thousand three hundred eighty four to determine the specific hash slot, ensuring keys are distributed pseudo randomly but consistently across the entire cluster's available slots.
-- The hash slot calculation happens automatically
-- CRC16(key) mod 16384 determines the slot
redis-cli cluster keyslot session:abc123
Real-world example
A developer troubleshooting uneven load across cluster nodes checks the hash slot calculation for their most frequently accessed keys, discovering a naming pattern that was accidentally concentrating too many keys onto a single node.
Clustering;Redis Performance Tuning & Benchmarking
What is a hash tag in Redis Cluster, and why would you use one to control which slot certain keys are assigned to?
IntermediateA hash tag is a portion of a key wrapped in curly braces, and when present, Redis Cluster only uses that specific portion for the hash slot calculation rather than the entire key, letting you deliberately force multiple related keys to land on the same slot and therefore the same node, which is required for operations that need to work with multiple keys together.
-- Both keys will be assigned to the same hash slot
-- because of the shared {user:123} hash tag
redis-cli set '{user:123}:profile' 'data'
redis-cli set '{user:123}:settings' 'data'
Real-world example
An application storing both a user's profile and settings under related keys uses hash tags to guarantee both keys always land on the same node, allowing them to be safely used together in a single multi key operation.
Clustering;Cluster Sharding & Hash Slots
How would you plan and execute resharding a Redis Cluster to add a new node and redistribute existing hash slots?
AdvancedYou add the new node to the cluster, then use a resharding tool or command to move a portion of hash slots, and the keys within them, from existing nodes to the new node, carefully doing this gradually to avoid overwhelming the cluster with data migration traffic while it continues serving live production requests.
redis-cli --cluster add-node newnode:6379 existingnode:6379
redis-cli --cluster reshard existingnode:6379
Real-world example
A growing e-commerce platform adds a fourth node to their three node Redis Cluster during a low traffic period, gradually resharding slots to the new node to spread out the increasing data volume without disrupting the live shopping experience.
Clustering;Redis Backup & Disaster Recovery
What happens to client requests during a hash slot migration, and how does Redis Cluster handle keys that are in the middle of being moved?
AdvancedDuring migration, a slot briefly exists in a special migrating or importing state on the source and destination nodes, and if a client requests a key that has already moved, the node responds with a redirect telling the client exactly which node now holds that key, allowing operations to continue correctly even while migration is actively in progress.
-- A client might receive an ASK or MOVED redirect
-- during an in progress slot migration
(error) ASK 3999 destinationnode:6379
Real-world example
A properly built Redis Cluster client library automatically follows ASK and MOVED redirects during a live resharding operation, ensuring the application experiences no errors even while data is actively being redistributed in the background.
Clustering;Connection Pooling & Client Libraries
How do you check the current distribution of hash slots and keys across the nodes in a Redis Cluster to identify potential imbalances?
IntermediateYou use the CLUSTER SLOTS or CLUSTER SHARDS command to see exactly which node owns which range of hash slots, and combine this with checking key counts per node, to identify if certain nodes are holding significantly more data or slots than others, which could indicate an imbalance worth addressing through resharding.
redis-cli cluster slots
redis-cli -h node1 dbsize
redis-cli -h node2 dbsize
Real-world example
A database administrator notices one node in their cluster holding twice as much data as the others after checking slot distribution and key counts, prompting a resharding operation to better balance the load.
Redis Monitoring & Observability;Clustering