0
0
Redisquery~20 mins

XREAD for reading entries in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Stream Reader Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What does this XREAD command return?
Given a Redis stream named mystream with entries:

1) 1609459200000-0: {"name":"Alice", "age":"30"}
2) 1609459260000-0: {"name":"Bob", "age":"25"}

What is the output of this command?

XREAD COUNT 1 STREAMS mystream 0
Redis
XREAD COUNT 1 STREAMS mystream 0
A[["mystream", [["1609459260000-0", {"name":"Bob", "age":"25"}]]]]
B[["mystream", [["0-0", {"name":"Alice", "age":"30"}]]]]
C[["mystream", [["1609459200000-0", {"name":"Alice", "age":"30"}]]]]
D[]
Attempts:
2 left
💡 Hint
The COUNT option limits the number of entries returned. The ID '0' means start from the beginning.
🧠 Conceptual
intermediate
1:30remaining
Understanding the ID parameter in XREAD
In the command XREAD STREAMS mystream 1609459200000-0, what does the ID 1609459200000-0 specify?
AStart reading entries strictly after the entry with ID 1609459200000-0
BStart reading entries from the end of the stream
CStart reading entries from the beginning of the stream
DStart reading entries including the entry with ID 1609459200000-0
Attempts:
2 left
💡 Hint
XREAD reads entries with IDs greater than the given ID.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in this XREAD command
Which option contains a syntax error when trying to read from stream mystream starting at ID 0?
Redis
XREAD STREAMS mystream 0
AXREAD COUNT 5 STREAMS mystream 0
BXREAD STREAMS mystream
CXREAD STREAMS mystream 0
DXREAD STREAMS mystream 0-0
Attempts:
2 left
💡 Hint
XREAD requires an ID after the stream name(s).
optimization
advanced
2:00remaining
Optimizing XREAD for multiple streams
You want to read new entries from two streams stream1 and stream2 starting from their latest entries. Which command is the most efficient to do this without reading old entries?
AXREAD STREAMS stream1 stream2 $ $
BXREAD STREAMS stream1 stream2 0 0
CXREAD COUNT 1 STREAMS stream1 stream2 $ $
DXREAD BLOCK 0 STREAMS stream1 stream2 0 0
Attempts:
2 left
💡 Hint
The special ID '$' means the latest entry in the stream.
🔧 Debug
expert
2:30remaining
Why does this XREAD command block indefinitely?
Consider the command:

XREAD BLOCK 0 STREAMS mystream 1609459260000-0

Given that mystream has no new entries after ID 1609459260000-0, what is the reason this command blocks indefinitely?
ABecause the COUNT option is missing, causing infinite blocking
BBecause the ID is invalid and causes the command to hang
CBecause the stream is empty and XREAD cannot return anything
DBecause BLOCK 0 means wait forever for new entries after the given ID
Attempts:
2 left
💡 Hint
BLOCK 0 means wait forever until new data arrives.