Challenge - 5 Problems
Redis Key Design Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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?
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
Attempts:
2 left
💡 Hint
Remember that SET creates string keys, not hashes.
✗ Incorrect
The keys user:1000:name and user:1000:age are separate string keys. The key user:1000 does not exist as a hash, so HGETALL returns an empty list.
📝 Syntax
intermediate2: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?
Attempts:
2 left
💡 Hint
ZADD syntax is ZADD key score member. ZREMRANGEBYSCORE removes by score range.
✗ Incorrect
Option D correctly adds the action with the timestamp as score and removes entries with scores less than or equal to 1619999940 (60 seconds ago).
🧠 Conceptual
advanced2: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?
Attempts:
2 left
💡 Hint
Think about how you find keys by pattern.
✗ Incorrect
Using colons creates a logical namespace that helps group related keys and makes pattern matching easier with commands like SCAN user:1000:*.
🔧 Debug
advanced2: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?
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
Attempts:
2 left
💡 Hint
What does GET return if key does not exist?
✗ Incorrect
GET returns nil if the key does not exist. Adding nil + 1 causes a Lua runtime error.
❓ optimization
expert2: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?
Attempts:
2 left
💡 Hint
Think about data structures that keep elements sorted by score.
✗ Incorrect
Redis sorted sets keep members sorted by score and support efficient range queries like top 10 with ZREVRANGE.