Challenge - 5 Problems
Redis Stream Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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:
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
Attempts:
2 left
💡 Hint
XRANGE returns entries in the given ID range inclusive, in ascending order.
✗ Incorrect
XRANGE returns all entries with IDs between the start and end IDs inclusive, ordered from smallest to largest ID.
❓ query_result
intermediate2: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
Attempts:
2 left
💡 Hint
XREVRANGE returns entries in the given ID range inclusive, in descending order.
✗ Incorrect
XREVRANGE returns all entries with IDs between the start and end IDs inclusive, ordered from largest to smallest ID.
📝 Syntax
advanced2:00remaining
Identify the syntax error in XRANGE usage
Which of the following XRANGE commands will cause a syntax error in Redis?
Attempts:
2 left
💡 Hint
XRANGE requires both start and end IDs to be specified.
✗ Incorrect
Option B is missing the end ID argument, causing a syntax error.
❓ optimization
advanced2: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?
Attempts:
2 left
💡 Hint
To get latest entries, use XREVRANGE with descending order and COUNT.
✗ Incorrect
XREVRANGE with + to - and COUNT 3 returns the latest 3 entries efficiently.
🧠 Conceptual
expert3: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:
and
respectively?
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?
Attempts:
2 left
💡 Hint
XRANGE and XREVRANGE include the boundary IDs specified.
✗ Incorrect
Both commands include entries with IDs equal to the start and end IDs. The order differs: XRANGE ascending, XREVRANGE descending.