Challenge - 5 Problems
Redis Cluster Multi-Key Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of this Redis cluster multi-key command?
Given a Redis cluster with keys
{user1}:name and {user1}:age stored in the same hash slot, what is the output of the command MGET {user1}:name {user1}:age if {user1}:name = "Alice" and {user1}:age = "30"?Redis
MGET {user1}:name {user1}:ageAttempts:
2 left
💡 Hint
Keys with the same hash tag (inside {}) are stored in the same slot and can be accessed together.
✗ Incorrect
In Redis Cluster, keys with the same hash tag (the part inside curly braces) are stored in the same slot, allowing multi-key commands like MGET to work without error. Since both keys exist with values "Alice" and "30", MGET returns both values in order.
🧠 Conceptual
intermediate2:00remaining
Why does Redis Cluster reject multi-key commands on keys without the same hash tag?
In Redis Cluster, why does a command like
MGET key1 key2 fail with a CROSSSLOT error if key1 and key2 do not share the same hash tag?Attempts:
2 left
💡 Hint
Think about how Redis Cluster distributes keys and why atomic operations need keys in the same slot.
✗ Incorrect
Redis Cluster partitions data by hash slots. Multi-key commands require all keys to be in the same slot to guarantee atomicity and avoid inconsistent states. If keys hash to different slots, the command fails with CROSSSLOT error.
📝 Syntax
advanced2:00remaining
Which command syntax correctly performs a multi-key increment in Redis Cluster?
You want to increment two counters stored as keys
{counter}:a and {counter}:b atomically in Redis Cluster. Which command syntax is valid?Attempts:
2 left
💡 Hint
Consider how Redis transactions work and how multi-key commands are handled in clusters.
✗ Incorrect
MULTI/EXEC starts a transaction block. Inside it, multiple commands like INCR can be queued and executed atomically. Option B correctly uses MULTI/EXEC with two INCR commands on keys sharing the same hash tag.
❓ optimization
advanced2:00remaining
How to optimize multi-key reads in Redis Cluster when keys have different hash tags?
You need to read values of keys
user:1:name and user:2:name in Redis Cluster, but they hash to different slots. What is the best approach to optimize multi-key reads?Attempts:
2 left
💡 Hint
Think about how to reduce network latency when keys are in different slots.
✗ Incorrect
Since keys are in different slots, MGET fails. Renaming keys may not be feasible. Lua scripts cannot access multiple slots atomically. Pipelining sends multiple commands in one go, reducing latency and improving performance.
🔧 Debug
expert2:00remaining
Why does this Redis Cluster multi-key command fail with CROSSSLOT error?
You run the command
MGET user:100:name user:101:name in a Redis Cluster and get the error: CROSSSLOT Keys in request don't hash to the same slot. Both keys exist. What is the root cause?Redis
MGET user:100:name user:101:name
Attempts:
2 left
💡 Hint
Check how Redis Cluster calculates hash slots for keys without explicit hash tags.
✗ Incorrect
Without explicit hash tags (the part inside {}), Redis Cluster hashes the entire key name, so keys with different suffixes hash to different slots. Multi-key commands require keys in the same slot, so this causes CROSSSLOT error.