0
0
Redisquery~10 mins

Priority queue pattern in Redis - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add an item with a priority to a Redis sorted set.

Redis
ZADD tasks [1] "task1"
Drag options to blanks, or click blank then click option'
Atasks
B"task1"
CZADD
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the member before the score
Using the key name as the score
2fill in blank
medium

Complete the code to get the highest priority item from the Redis sorted set.

Redis
ZRANGE tasks [1] [2] WITHSCORES
Drag options to blanks, or click blank then click option'
A1
B0
C-1
D-2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 0 returns the lowest priority item
Using positive indexes to get the last element
3fill in blank
hard

Fix the error in the code to remove the highest priority item from the sorted set.

Redis
ZREM tasks [1]
Drag options to blanks, or click blank then click option'
A"task1"
BZRANGE tasks -1 -1
CZPOPMAX tasks
DZREM tasks -1
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to remove by index or command instead of member name
Using ZREM with a negative index
4fill in blank
hard

Fill both blanks to atomically pop the highest priority item from the sorted set.

Redis
ZPOPMAX [1] [2]
Drag options to blanks, or click blank then click option'
Atasks
B1
C0
Dtask1
Attempts:
3 left
💡 Hint
Common Mistakes
Using member name instead of key as first argument
Using 0 as count which pops nothing
5fill in blank
hard

Fill all three blanks to add a task with priority, then get and remove the highest priority task.

Redis
ZADD [1] [2] "task2"
result = ZPOPMAX [3] 1
Drag options to blanks, or click blank then click option'
Atasks
B5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for add and pop
Using a string instead of a number for priority