0
0
Redisquery~20 mins

Key design patterns in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Key Design Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this Redis command sequence?
Given the following Redis commands executed in order:

1. SET user:1000:name "Alice"
2. SET user:1000:age 30
3. HGETALL user:1000

What will be the output of the last command?
Redis
SET user:1000:name "Alice"
SET user:1000:age 30
HGETALL user:1000
AAn empty list ([]) because user:1000 is not a hash key
B["user:1000:name", "Alice", "user:1000:age", "30"]
C["name", "Alice", "age", "30"]
DError: WRONGTYPE Operation against a key holding the wrong kind of value
Attempts:
2 left
💡 Hint
Remember that SET creates string keys, not hashes.
📝 Syntax
intermediate
2:00remaining
Which Redis command correctly implements a simple rate limiter using a sorted set?
You want to limit a user to 5 actions per minute using Redis sorted sets. Which command correctly adds a timestamp to the sorted set for user:123 and removes old entries older than 60 seconds?
A
ZADD user:123 action1 1620000000
ZREMRANGEBYSCORE user:123 -inf 1619999940
B
ZADD user:123 action1 1620000000
ZREMRANGEBYSCORE user:123 1619999940 +inf
C
ZADD user:123 1620000000 action1
ZREMRANGEBYSCORE user:123 1619999940 +inf
D
ZADD user:123 1620000000 action1
ZREMRANGEBYSCORE user:123 -inf 1619999940
Attempts:
2 left
💡 Hint
ZADD syntax is ZADD key score member. ZREMRANGEBYSCORE removes by score range.
🧠 Conceptual
advanced
2:00remaining
Why is the Redis key naming pattern with colons (:) recommended?
Redis keys often use colons to separate parts, like user:1000:profile. What is the main advantage of this pattern?
AIt helps organize keys logically and supports efficient use of commands like SCAN and KEYS with patterns.
BIt allows Redis to automatically create nested data structures.
CIt compresses keys to save memory in Redis.
DIt enables Redis to enforce access control on key namespaces.
Attempts:
2 left
💡 Hint
Think about how you find keys by pattern.
🔧 Debug
advanced
2:00remaining
What error occurs when running this Redis Lua script?
Consider this Lua script run in Redis:

local val = redis.call('GET', 'counter')
return val + 1

What error will this script produce if 'counter' key does not exist?
Redis
local val = redis.call('GET', 'counter')
return val + 1
ARedis command error because GET is invalid in Lua
Bnil value error because val is nil and cannot be added to 1
CReturns 1 because nil is treated as 0
DSyntax error in Lua script
Attempts:
2 left
💡 Hint
What does GET return if key does not exist?
optimization
expert
2:00remaining
Which Redis data structure and pattern is best for implementing a leaderboard with frequent score updates and top 10 queries?
You want to build a leaderboard that updates user scores frequently and retrieves the top 10 users efficiently. Which Redis data structure and pattern is best suited?
AUse a Redis hash with user IDs as fields and scores as values
BUse a Redis list to push scores and sort on retrieval
CUse a Redis sorted set with user IDs as members and scores as scores
DUse multiple string keys per user to store scores and sort externally
Attempts:
2 left
💡 Hint
Think about data structures that keep elements sorted by score.