Hint: XREVRANGE uses '+' then '-' for newest to oldest [OK]
Common Mistakes:
Swapping '+' and '-' in range
Using XRANGE instead of XREVRANGE
Incorrect start or end IDs
3. Given a Redis stream mystream with entries: 1609459200000-0: {"name":"Alice"} 1609459260000-0: {"name":"Bob"} 1609459320000-0: {"name":"Carol"} What will be the result of XRANGE mystream 1609459200000-0 1609459260000-0?
medium
A. [["1609459320000-0", {"name":"Carol"}]]
B. [["1609459260000-0", {"name":"Bob"}], ["1609459200000-0", {"name":"Alice"}]]
C. [["1609459200000-0", {"name":"Alice"}], ["1609459260000-0", {"name":"Bob"}]]
D. Empty list
Solution
Step 1: Understand XRANGE with ID range
XRANGE returns entries from start ID to end ID in order from oldest to newest.
Step 2: Identify matching entries
Entries with IDs 1609459200000-0 and 1609459260000-0 fall within the range, so both are returned in order.
Final Answer:
[["1609459200000-0", {"name":"Alice"}], ["1609459260000-0", {"name":"Bob"}]] -> Option C
Quick Check:
XRANGE returns oldest to newest in range [OK]
Hint: XRANGE returns entries in ascending ID order [OK]
Common Mistakes:
Expecting reverse order output
Including entries outside the range
Confusing XRANGE with XREVRANGE
4. You run the command XREVRANGE mystream - + COUNT 3 on a stream with more than 3 entries but get an empty list. What is the likely cause?
medium
A. The range start and end IDs are reversed; XREVRANGE expects '+' then '-'.
B. COUNT cannot be used with XREVRANGE.
C. The stream key 'mystream' does not exist.
D. XREVRANGE requires numeric IDs only.
Solution
Step 1: Check XREVRANGE range order
XREVRANGE reads from newest to oldest, so the start ID must be '+' and end ID '-'. Using '-' then '+' reverses the order and results in an empty list.
Step 2: Verify other options
COUNT is valid with XREVRANGE, a missing key returns empty list (but stream exists with >3 entries), and special IDs like -/+ are valid.
Final Answer:
The range start and end IDs are reversed; XREVRANGE expects '+' then '-'. -> Option A
Quick Check:
XREVRANGE range must be '+' to '-' [OK]
Hint: XREVRANGE range must start with '+' and end with '-' [OK]
Common Mistakes:
Swapping start and end IDs in XREVRANGE
Assuming COUNT is invalid
Confusing the empty result with missing key
5. You want to retrieve the 3 newest entries from a stream mystream but only those with IDs greater than 1609459200000-0. Which command achieves this correctly?
hard
A. XREVRANGE mystream + 1609459200000-0 COUNT 3
B. XRANGE mystream 1609459200000-0 + COUNT 3
C. XREVRANGE mystream 1609459200000-0 + COUNT 3
D. XRANGE mystream + 1609459200000-0 COUNT 3
Solution
Step 1: Understand the requirement
We want the 3 newest entries with IDs greater than 1609459200000-0, so we read backwards from newest (+) down to that ID.
Step 2: Choose correct command and range
XREVRANGE reads newest to oldest, so range '+' to '1609459200000-0' with COUNT 3 gets newest entries above that ID.
Step 3: Eliminate wrong options
XRANGE reads oldest to newest, so XRANGE mystream 1609459200000-0 + COUNT 3 and D read forward. XREVRANGE mystream 1609459200000-0 + COUNT 3 reverses range order for XREVRANGE, causing error.
Final Answer:
XREVRANGE mystream + 1609459200000-0 COUNT 3 -> Option A
Quick Check:
Newest entries above ID = XREVRANGE + to ID [OK]
Hint: Use XREVRANGE + to ID for newest entries above ID [OK]
Common Mistakes:
Using XRANGE instead of XREVRANGE for newest entries
Reversing range IDs in XREVRANGE
Omitting COUNT to limit results
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.