0
0
Redisquery~5 mins

LRANGE for reading elements in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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"]?
A["z", "w"]
B["x", "y", "z"]
C["y", "z", "w"]
D["y", "z"]
If you want to get the last element of a list using LRANGE, which indexes do you use?
A-1 -1
B0 0
C0 -1
D-2 -1
What will LRANGE return if the start index is greater than the stop index?
AAn error
BAn empty list
CThe whole list
DThe first element only
How does LRANGE treat the stop index?
AIgnored
BExclusive (stop element not included)
CAlways zero
DInclusive (stop element included)
If a list has 5 elements, what does LRANGE mylist 0 10 return?
AThe first 5 elements
BAn empty list
CAn error because 10 is out of range
DOnly the first element
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.