0
0
Redisquery~20 mins

Stream entry IDs in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stream ID Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this XADD command?
Consider the Redis command:
XADD mystream * sensor-id 1234 temperature 19.8
What does the command return?
Redis
XADD mystream * sensor-id 1234 temperature 19.8
AAn error message about missing stream key
BThe string "OK"
CThe number of fields added, e.g., 2
DA generated stream entry ID in the format <millisecondsTime>-<sequenceNumber>, e.g., "1687000000000-0"
Attempts:
2 left
💡 Hint
XADD returns the ID of the added entry, which is a timestamp plus a sequence number.
🧠 Conceptual
intermediate
2:00remaining
What does the stream entry ID '1687000000000-5' represent?
In Redis streams, what do the two parts of the entry ID '1687000000000-5' mean?
AThe first part is a Unix timestamp in milliseconds; the second part is a sequence number for entries with the same timestamp
BThe first part is the stream length; the second part is the entry's position
CThe first part is the server's process ID; the second part is the entry's priority
DThe first part is the entry's hash; the second part is a random number
Attempts:
2 left
💡 Hint
Think about how Redis ensures unique IDs for entries added at the same millisecond.
📝 Syntax
advanced
2:00remaining
Which XADD command syntax is correct to add an entry with a custom ID?
You want to add an entry to 'mystream' with ID '1687000000000-0' and fields 'name'='sensor1' and 'value'='42'. Which command is correct?
AXADD mystream 1687000000000-0 name sensor1 value 42
BXADD mystream * 1687000000000-0 name sensor1 value 42
CXADD mystream name sensor1 value 42 1687000000000-0
DXADD mystream ID 1687000000000-0 name sensor1 value 42
Attempts:
2 left
💡 Hint
The ID comes immediately after the stream key in XADD syntax.
optimization
advanced
2:00remaining
How to efficiently trim a Redis stream to keep only the last 1000 entries?
Which command efficiently trims the stream 'mystream' to keep only the latest 1000 entries?
AXTRIM mystream MAXLEN 1000
BXTRIM mystream MAXLEN ~ 1000
CXTRIM mystream MINLEN 1000
DXTRIM mystream COUNT 1000
Attempts:
2 left
💡 Hint
Use approximate trimming for better performance.
🔧 Debug
expert
2:00remaining
Why does this XREAD command return no entries?
You run:
XREAD COUNT 2 STREAMS mystream 1687000000000-5
But get no results, even though the stream has entries. Why?
ABecause the stream key 'mystream' does not exist
BBecause the COUNT parameter must be after STREAMS keyword
CBecause XREAD returns entries with IDs strictly greater than the given ID, so if no newer entries exist, it returns nothing
DBecause the ID '1687000000000-5' is invalid format
Attempts:
2 left
💡 Hint
XREAD returns entries with IDs greater than the one specified, not equal or less.