Challenge - 5 Problems
LINDEX Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of LINDEX for a valid positive index?
Given a Redis list
mylist with elements ["apple", "banana", "cherry"], what is the output of LINDEX mylist 1?Redis
LINDEX mylist 1Attempts:
2 left
💡 Hint
Remember that Redis lists are zero-indexed, so index 1 is the second element.
✗ Incorrect
LINDEX returns the element at the specified zero-based index. Index 1 corresponds to the second element, which is "banana".
❓ query_result
intermediate1:30remaining
What does LINDEX return for a negative index?
Given a Redis list
colors with elements ["red", "green", "blue", "yellow"], what is the output of LINDEX colors -2?Redis
LINDEX colors -2Attempts:
2 left
💡 Hint
Negative indexes count from the end of the list, starting at -1 for the last element.
✗ Incorrect
Index -1 is the last element "yellow", so -2 is the second last element "blue".
📝 Syntax
advanced1:30remaining
Which LINDEX command syntax is correct?
Which of the following Redis commands correctly uses LINDEX to get the first element of list
tasks?Attempts:
2 left
💡 Hint
LINDEX requires the key first, then the index as an integer.
✗ Incorrect
The correct syntax is
LINDEX key index. Option B follows this format with index 0 for the first element.❓ query_result
advanced1:30remaining
What is the output when LINDEX index is out of range?
Given a Redis list
numbers with elements ["one", "two", "three"], what is the output of LINDEX numbers 5?Redis
LINDEX numbers 5Attempts:
2 left
💡 Hint
If the index is outside the list range, Redis returns nil.
✗ Incorrect
Since index 5 is beyond the last element (index 2), Redis returns nil indicating no element found.
🧠 Conceptual
expert2:00remaining
How does LINDEX handle concurrent modifications?
If a Redis list
queue is modified (elements added or removed) by other clients while a client runs LINDEX queue 2, what can be said about the returned value?Attempts:
2 left
💡 Hint
Think about how Redis commands are atomic and reflect the current state at execution.
✗ Incorrect
Redis commands are atomic and see the list state at the moment of execution, so LINDEX returns the element at index 2 at that time, including any concurrent changes.