0
0
Redisquery~20 mins

Multi-key operations in cluster in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Cluster Multi-Key Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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}:age
A[null, null]
B["Alice"]
CError: CROSSSLOT Keys in request don't hash to the same slot
D["Alice", "30"]
Attempts:
2 left
💡 Hint
Keys with the same hash tag (inside {}) are stored in the same slot and can be accessed together.
🧠 Conceptual
intermediate
2: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?
ABecause keys must be in the same hash slot to ensure atomicity and consistency of multi-key operations.
BBecause keys with different names cannot be accessed together.
CBecause Redis Cluster does not support multi-key commands at all.
DBecause the keys are stored in the same slot but the command syntax is invalid.
Attempts:
2 left
💡 Hint
Think about how Redis Cluster distributes keys and why atomic operations need keys in the same slot.
📝 Syntax
advanced
2: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?
AINCR {counter}:a {counter}:b
B
MULTI
INCR {counter}:a
INCR {counter}:b
EXEC
CMSET {counter}:a {counter}:b
DINCR {counter}:a; INCR {counter}:b
Attempts:
2 left
💡 Hint
Consider how Redis transactions work and how multi-key commands are handled in clusters.
optimization
advanced
2: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?
AUse MGET command directly on both keys.
BRename keys to have the same hash tag and use MGET.
CUse pipelining to send multiple GET commands in one network round-trip.
DUse Lua scripting to read both keys atomically.
Attempts:
2 left
💡 Hint
Think about how to reduce network latency when keys are in different slots.
🔧 Debug
expert
2: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
AThe keys hash to different slots because they lack a common hash tag.
BThe keys do not exist in the cluster.
CThe MGET command is not supported in Redis Cluster.
DThe keys are locked by another client.
Attempts:
2 left
💡 Hint
Check how Redis Cluster calculates hash slots for keys without explicit hash tags.