0
0
Redisquery~20 mins

List vs sorted set for sequences in Redis - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Sequence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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
Redis
LPUSH mylist 10
LPUSH mylist 20
LRANGE mylist 0 -1
A["20", "10"]
B["10", "20"]
C["10"]
D[]
Attempts:
2 left
💡 Hint
Remember LPUSH adds elements to the head of the list.
query_result
intermediate
2: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
Redis
ZADD myzset 5 "apple"
ZADD myzset 1 "banana"
ZADD myzset 3 "cherry"
ZRANGE myzset 0 -1 WITHSCORES
A["cherry", "3", "banana", "1", "apple", "5"]
B["apple", "5", "banana", "1", "cherry", "3"]
C["apple", "banana", "cherry"]
D["banana", "1", "cherry", "3", "apple", "5"]
Attempts:
2 left
💡 Hint
Sorted sets order elements by score ascending.
🧠 Conceptual
advanced
2: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?
ARedis Sorted Set, because it automatically orders by score and allows duplicates.
BRedis List, because it preserves insertion order and allows duplicates.
CRedis Hash, because it stores key-value pairs efficiently.
DRedis Set, because it stores unique elements without order.
Attempts:
2 left
💡 Hint
Consider if duplicates and order matter.
📝 Syntax
advanced
2: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?
AZADD myzset "orange" 10
BZADD myzset 10 "orange"
CZADD myzset 5 "grape"
DZADD myzset 3 "melon"
Attempts:
2 left
💡 Hint
Check the order of arguments for ZADD command.
optimization
expert
2: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?
AZRANGE myzset -10 -1 WITHSCORES
BZRANGEBYSCORE myzset +inf -inf LIMIT 0 10
CZREVRANGE myzset 0 9 WITHSCORES
DZREM myzset 0 9
Attempts:
2 left
💡 Hint
Think about ordering and direction of retrieval.