Challenge - 5 Problems
Redis Priority Queue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Retrieve highest priority item from a Redis sorted set
Given a Redis sorted set named
tasks where scores represent priority (lower score means higher priority), which command retrieves the task with the highest priority?Redis
ZADD tasks 10 "task1" 5 "task2" 20 "task3"
Attempts:
2 left
💡 Hint
Remember that lower scores mean higher priority in Redis sorted sets.
✗ Incorrect
ZRANGE with 0 0 returns the element with the lowest score (highest priority). ZPOPMIN removes the element, which is not asked here.
📝 Syntax
intermediate2:00remaining
Correct syntax to add an item with priority to Redis sorted set
Which of the following commands correctly adds an item
job42 with priority score 15 to a Redis sorted set named job_queue?Attempts:
2 left
💡 Hint
The correct order is: ZADD key score member
✗ Incorrect
ZADD expects the score first, then the member. Option B follows this order correctly.
❓ optimization
advanced2:00remaining
Efficiently pop the highest priority item from a Redis sorted set
You want to remove and get the highest priority item (lowest score) from a Redis sorted set
tasks. Which command is the most efficient and atomic way to do this?Attempts:
2 left
💡 Hint
Look for a command that both returns and removes the element in one step.
✗ Incorrect
ZPOPMIN atomically pops the element with the lowest score, making it efficient and safe for concurrent use.
🧠 Conceptual
advanced2:00remaining
Understanding priority queue behavior in Redis sorted sets
In a Redis sorted set used as a priority queue, what does the score represent and how does it affect the order of elements?
Attempts:
2 left
💡 Hint
Think about how Redis sorted sets order elements by score.
✗ Incorrect
Redis sorted sets order elements by score in ascending order, so lower scores come first, representing higher priority.
🔧 Debug
expert3:00remaining
Identify the error in this Redis command sequence for priority queue
You want to add a job with priority 10 and then pop the highest priority job from
job_queue. Which command sequence will cause an error?Redis
ZADD job_queue 10 job100 ZPOPMIN job_queue 1
Attempts:
2 left
💡 Hint
Check the order of arguments in ZADD command.
✗ Incorrect
Option C uses incorrect argument order in ZADD (member before score), causing a syntax error.