Challenge - 5 Problems
Stream ID Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this XADD command?
Consider the Redis command:
What does the command return?
XADD mystream * sensor-id 1234 temperature 19.8What does the command return?
Redis
XADD mystream * sensor-id 1234 temperature 19.8
Attempts:
2 left
💡 Hint
XADD returns the ID of the added entry, which is a timestamp plus a sequence number.
✗ Incorrect
The XADD command adds an entry to a Redis stream and returns the entry ID generated automatically when using '*'. This ID looks like a timestamp in milliseconds followed by a sequence number separated by a dash.
🧠 Conceptual
intermediate2: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?
Attempts:
2 left
💡 Hint
Think about how Redis ensures unique IDs for entries added at the same millisecond.
✗ Incorrect
Redis stream entry IDs consist of a millisecond timestamp and a sequence number to differentiate entries added in the same millisecond.
📝 Syntax
advanced2: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?
Attempts:
2 left
💡 Hint
The ID comes immediately after the stream key in XADD syntax.
✗ Incorrect
The XADD command syntax is: XADD key ID field value [field value ...]. To specify a custom ID, place it right after the stream key.
❓ optimization
advanced2: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?
Attempts:
2 left
💡 Hint
Use approximate trimming for better performance.
✗ Incorrect
Using XTRIM with MAXLEN ~ 1000 trims the stream approximately to 1000 entries, which is faster than exact trimming.
🔧 Debug
expert2:00remaining
Why does this XREAD command return no entries?
You run:
But get no results, even though the stream has entries. Why?
XREAD COUNT 2 STREAMS mystream 1687000000000-5But get no results, even though the stream has entries. Why?
Attempts:
2 left
💡 Hint
XREAD returns entries with IDs greater than the one specified, not equal or less.
✗ Incorrect
XREAD returns entries with IDs strictly greater than the ID specified. If no such entries exist, it returns no results.