Challenge - 5 Problems
Redis Sequence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of adding elements to a Redis List
What will be the output of the following Redis commands?
Commands:
LPUSH mylist 10
LPUSH mylist 20
LRANGE mylist 0 -1
Commands:
LPUSH mylist 10
LPUSH mylist 20
LRANGE mylist 0 -1
Redis
LPUSH mylist 10 LPUSH mylist 20 LRANGE mylist 0 -1
Attempts:
2 left
💡 Hint
Remember LPUSH adds elements to the head of the list.
✗ Incorrect
LPUSH adds elements to the start of the list, so the last pushed element appears first when reading from 0 to -1.
❓ query_result
intermediate2:00remaining
Output of adding elements to a Redis Sorted Set
What will be the output of the following Redis commands?
Commands:
ZADD myzset 5 "apple"
ZADD myzset 1 "banana"
ZADD myzset 3 "cherry"
ZRANGE myzset 0 -1 WITHSCORES
Commands:
ZADD myzset 5 "apple"
ZADD myzset 1 "banana"
ZADD myzset 3 "cherry"
ZRANGE myzset 0 -1 WITHSCORES
Redis
ZADD myzset 5 "apple" ZADD myzset 1 "banana" ZADD myzset 3 "cherry" ZRANGE myzset 0 -1 WITHSCORES
Attempts:
2 left
💡 Hint
Sorted sets order elements by score ascending.
✗ Incorrect
ZRANGE returns elements ordered by score from lowest to highest. Scores are included with WITHSCORES.
🧠 Conceptual
advanced2:00remaining
Choosing between Redis List and Sorted Set for sequence with duplicates
You want to store a sequence of events that can have duplicate timestamps and need to preserve insertion order. Which Redis data structure is best suited?
Attempts:
2 left
💡 Hint
Consider if duplicates and order matter.
✗ Incorrect
Redis Lists preserve insertion order and allow duplicates. Sorted Sets do not allow duplicate members and order by score.
📝 Syntax
advanced2:00remaining
Identify the invalid Redis command for adding to a Sorted Set
Which of the following commands will cause a syntax error when adding elements to a Redis Sorted Set?
Attempts:
2 left
💡 Hint
Check the order of arguments for ZADD command.
✗ Incorrect
ZADD syntax requires the score first, then the member. Option A reverses them causing syntax error.
❓ optimization
expert2:00remaining
Optimizing retrieval of top N recent events with timestamps in Redis
You store events with timestamps as scores in a Redis Sorted Set. You want to efficiently retrieve the 10 most recent events. Which command is best?
Attempts:
2 left
💡 Hint
Think about ordering and direction of retrieval.
✗ Incorrect
ZREVRANGE returns elements from highest to lowest score, so it efficiently gets the most recent events.