0
0
Redisquery~20 mins

LRANGE for reading elements in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LRANGE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1:30remaining
What does this LRANGE command return?
Given a Redis list mylist with elements ["a", "b", "c", "d", "e"], what is the output of the command LRANGE mylist 1 3?
Redis
LRANGE mylist 1 3
A["a", "b", "c"]
B["b", "c", "d"]
C["c", "d", "e"]
D["b", "c", "d", "e"]
Attempts:
2 left
💡 Hint
Remember that LRANGE uses zero-based indexing and includes both start and end positions.
query_result
intermediate
1:30remaining
What is the output of LRANGE with negative indices?
If mylist contains ["x", "y", "z", "w"], what does LRANGE mylist -3 -1 return?
Redis
LRANGE mylist -3 -1
A["y", "z", "w"]
B["x", "y", "z"]
C["w"]
D["z", "w"]
Attempts:
2 left
💡 Hint
Negative indices count from the end of the list, starting at -1 for the last element.
📝 Syntax
advanced
1:00remaining
Which LRANGE command is syntactically correct?
Identify the syntactically valid LRANGE command to get elements from index 2 to 4 from list mylist.
ALRANGE mylist 2-4
BLRANGE mylist 2,4
CLRANGE mylist (2 4)
DLRANGE mylist 2 4
Attempts:
2 left
💡 Hint
LRANGE syntax requires the key followed by two separate integer arguments for start and stop.
optimization
advanced
2:00remaining
Efficiently reading the last 5 elements of a large list
You have a Redis list biglist with 1 million elements. Which LRANGE command efficiently retrieves the last 5 elements?
ALRANGE biglist 999995 999999
BLRANGE biglist 0 4
CLRANGE biglist -5 -1
DLRANGE biglist 999995 -1
Attempts:
2 left
💡 Hint
Negative indices are a convenient way to access elements from the end without calculating exact positions.
🧠 Conceptual
expert
1:30remaining
What happens if LRANGE start index is greater than end index?
Consider a Redis list mylist with elements ["p", "q", "r"]. What is the result of LRANGE mylist 2 1?
AAn empty list []
BA syntax error
CReturns elements from index 1 to 2
DReturns all elements
Attempts:
2 left
💡 Hint
LRANGE returns elements from start to end index inclusive, but start must be less or equal to end.