0
0
Redisquery~20 mins

XRANGE and XREVRANGE in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Stream Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of XRANGE with specific ID range
Given a Redis stream named mystream with entries:

1) ID: 1609459200000-0, fields: {"name": "Alice", "age": "30"}
2) ID: 1609459201000-0, fields: {"name": "Bob", "age": "25"}
3) ID: 1609459202000-0, fields: {"name": "Charlie", "age": "35"}

What is the output of the command:
XRANGE mystream 1609459200000-0 1609459201000-0
Redis
XRANGE mystream 1609459200000-0 1609459201000-0
A[["1609459200000-0", {"name": "Alice", "age": "30"}], ["1609459201000-0", {"name": "Bob", "age": "25"}]]
B[["1609459201000-0", {"name": "Bob", "age": "25"}], ["1609459202000-0", {"name": "Charlie", "age": "35"}]]
C[["1609459200000-0", {"name": "Alice", "age": "30"}], ["1609459202000-0", {"name": "Charlie", "age": "35"}]]
D[]
Attempts:
2 left
💡 Hint
XRANGE returns entries in the given ID range inclusive, in ascending order.
query_result
intermediate
2:00remaining
Output of XREVRANGE with specific ID range
Using the same Redis stream mystream as before, what is the output of:
XREVRANGE mystream 1609459202000-0 1609459200000-0
Redis
XREVRANGE mystream 1609459202000-0 1609459200000-0
A[["1609459202000-0", {"name": "Charlie", "age": "35"}], ["1609459201000-0", {"name": "Bob", "age": "25"}], ["1609459200000-0", {"name": "Alice", "age": "30"}]]
B[["1609459200000-0", {"name": "Alice", "age": "30"}], ["1609459201000-0", {"name": "Bob", "age": "25"}]]
C[["1609459201000-0", {"name": "Bob", "age": "25"}], ["1609459202000-0", {"name": "Charlie", "age": "35"}]]
D[]
Attempts:
2 left
💡 Hint
XREVRANGE returns entries in the given ID range inclusive, in descending order.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in XRANGE usage
Which of the following XRANGE commands will cause a syntax error in Redis?
AXRANGE mystream 1609459200000-0 1609459201000-0
BXRANGE mystream 1609459200000-0
CXRANGE mystream 1609459200000-0 1609459201000-0 COUNT 2
DXRANGE mystream - +
Attempts:
2 left
💡 Hint
XRANGE requires both start and end IDs to be specified.
optimization
advanced
2:00remaining
Optimizing XRANGE with COUNT
You want to fetch only the latest 3 entries from a Redis stream mystream. Which command is the most efficient?
AXRANGE mystream - + COUNT 3
BXREVRANGE mystream - + COUNT 3
CXRANGE mystream + - COUNT 3
DXREVRANGE mystream + - COUNT 3
Attempts:
2 left
💡 Hint
To get latest entries, use XREVRANGE with descending order and COUNT.
🧠 Conceptual
expert
3:00remaining
Understanding XRANGE and XREVRANGE ID boundaries
Consider a Redis stream mystream with entries having IDs:
1000-0, 1000-1, 1001-0, 1002-0.

What will be the output of:
XRANGE mystream 1000-1 1002-0

and
XREVRANGE mystream 1002-0 1000-1

respectively?
AXRANGE returns entries with IDs 1000-1, 1001-0; XREVRANGE returns entries 1002-0, 1001-0
BXRANGE returns entries with IDs 1000-0, 1000-1, 1001-0; XREVRANGE returns entries 1002-0, 1001-0, 1000-0
CXRANGE returns entries with IDs 1000-1, 1001-0, 1002-0; XREVRANGE returns entries 1002-0, 1001-0, 1000-1
DBoth commands return empty lists because the ranges are invalid
Attempts:
2 left
💡 Hint
XRANGE and XREVRANGE include the boundary IDs specified.