Recall & Review
beginner
What does the LRANGE command do in Redis?
LRANGE returns a specified range of elements from a list stored at a given key. It reads elements between the start and stop indexes.
Click to reveal answer
beginner
How do you specify the range of elements to read with LRANGE?
You provide two numbers: the start index and the stop index. Both are zero-based and inclusive.
Click to reveal answer
intermediate
What happens if the stop index in LRANGE is larger than the list length?
LRANGE will return elements up to the end of the list without error.
Click to reveal answer
intermediate
How does LRANGE handle negative indexes?
Negative indexes count from the end of the list. For example, -1 is the last element, -2 is the second last, and so on.
Click to reveal answer
beginner
Example: What does LRANGE mylist 0 2 return if mylist = ["a", "b", "c", "d"]?
It returns ["a", "b", "c"] — the first three elements from index 0 to 2 inclusive.
Click to reveal answer
What does LRANGE mylist 1 3 return if mylist = ["x", "y", "z", "w"]?
✗ Incorrect
Indexes 1 to 3 include elements at positions 1, 2, and 3: "y", "z", and "w".
If you want to get the last element of a list using LRANGE, which indexes do you use?
✗ Incorrect
Using -1 for both start and stop returns only the last element.
What will LRANGE return if the start index is greater than the stop index?
✗ Incorrect
LRANGE returns an empty list if start > stop.
How does LRANGE treat the stop index?
✗ Incorrect
The stop index is inclusive, so the element at that index is included in the result.
If a list has 5 elements, what does LRANGE mylist 0 10 return?
✗ Incorrect
LRANGE returns all elements up to the end if stop index is beyond list length.
Explain how to use LRANGE to read elements from a Redis list, including how indexes work.
Think about how you pick a slice of a list using start and stop positions.
You got /5 concepts.
Describe what happens when LRANGE is used with indexes outside the list's length or with negative indexes.
Consider how LRANGE handles boundaries and negative numbers.
You got /4 concepts.