0
0
Redisquery~20 mins

Priority queue pattern in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Priority Queue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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"
AZRANGE tasks 0 0 WITHSCORES
BZPOPMIN tasks 1
CZREVRANGE tasks 0 0 WITHSCORES
DZRANGE tasks -1 -1 WITHSCORES
Attempts:
2 left
💡 Hint
Remember that lower scores mean higher priority in Redis sorted sets.
📝 Syntax
intermediate
2: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?
AZADD job_queue job42 15
BZADD job_queue 15 job42
CZADD job_queue (15) job42
DZADD job_queue "job42" 15
Attempts:
2 left
💡 Hint
The correct order is: ZADD key score member
optimization
advanced
2: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?
AZPOPMIN tasks 1
BZRANGE tasks 0 0 WITHSCORES followed by ZREM tasks <member>
CZREVRANGE tasks 0 0 WITHSCORES
DZPOP tasks 1
Attempts:
2 left
💡 Hint
Look for a command that both returns and removes the element in one step.
🧠 Conceptual
advanced
2: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?
AScore represents priority; elements are ordered randomly regardless of score.
BScore represents priority; higher scores mean higher priority and appear first.
CScore is ignored; elements are ordered by insertion time.
DScore represents priority; lower scores mean higher priority and appear first.
Attempts:
2 left
💡 Hint
Think about how Redis sorted sets order elements by score.
🔧 Debug
expert
3: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
AZADD job_queue 10 job100\nZPOPMIN job_queue 1
BZADD job_queue 10 job100\nZRANGE job_queue 0 0
CZADD job_queue job100 10\nZPOPMIN job_queue 1
DZADD job_queue 10 job100\nZREM job_queue job100
Attempts:
2 left
💡 Hint
Check the order of arguments in ZADD command.