Challenge - 5 Problems
Redis List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this Redis command sequence?
Consider the following Redis commands executed in order:
1. LPUSH mylist a
2. RPUSH mylist b
3. LRANGE mylist 0 -1
What will be the output of the LRANGE command?
1. LPUSH mylist a
2. RPUSH mylist b
3. LRANGE mylist 0 -1
What will be the output of the LRANGE command?
Redis
LPUSH mylist a RPUSH mylist b LRANGE mylist 0 -1
Attempts:
2 left
💡 Hint
LPUSH adds to the start, RPUSH adds to the end. LRANGE returns the list from start to end indexes.
✗ Incorrect
LPUSH adds 'a' to the start, so list is ['a']. RPUSH adds 'b' to the end, so list becomes ['b', 'a']. LRANGE 0 -1 returns all elements in order.
🧠 Conceptual
intermediate1:30remaining
Why are Redis lists suitable for ordered sequences?
Which of the following best explains why Redis lists are used to handle ordered sequences?
Attempts:
2 left
💡 Hint
Think about how elements are added and retrieved in order.
✗ Incorrect
Redis lists keep elements in the order they were added and support fast insertion/removal at the start or end, making them ideal for ordered sequences.
📝 Syntax
advanced1:00remaining
Which Redis command syntax correctly inserts an element at the end of a list?
Select the correct Redis command to add the element 'x' to the end of the list named 'mylist'.
Attempts:
2 left
💡 Hint
RPUSH adds to the right (end), LPUSH adds to the left (start).
✗ Incorrect
RPUSH is the correct command to add an element at the end of a Redis list. LPUSH adds at the start. PUSHEND and APPEND are invalid commands.
❓ optimization
advanced1:30remaining
How to efficiently retrieve the last 10 elements of a very large Redis list?
You have a Redis list with millions of elements. Which command is the most efficient to get the last 10 elements without retrieving the entire list?
Attempts:
2 left
💡 Hint
Negative indexes in LRANGE count from the end.
✗ Incorrect
LRANGE with negative indexes (-10 to -1) efficiently retrieves the last 10 elements without scanning the entire list. Other options either get the first elements or remove elements.
🔧 Debug
expert2:00remaining
What error occurs with this Redis command sequence?
Given an empty Redis database, what happens when you run:
1. LPOP mylist
2. LRANGE mylist 0 -1
Choose the correct outcome.
1. LPOP mylist
2. LRANGE mylist 0 -1
Choose the correct outcome.
Attempts:
2 left
💡 Hint
Consider how Redis behaves when popping from an empty list and querying an empty list.
✗ Incorrect
LPOP on an empty list returns nil (no element). LRANGE on an empty list returns an empty list []. No errors occur.