0
0
Redisquery~20 mins

XADD for adding entries in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Stream Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What does this XADD command return?
Consider the Redis command:
XADD mystream * sensor-id 1234 temperature 19.8
What is the output of this command?
Redis
XADD mystream * sensor-id 1234 temperature 19.8
AAn error message because * is invalid here
BAn integer representing the number of fields added, e.g., 2
CThe string 'OK' indicating success
DA string representing the ID of the added entry, e.g., '1657891234567-0'
Attempts:
2 left
💡 Hint
XADD returns the ID of the new entry added to the stream.
📝 Syntax
intermediate
2:00remaining
Which XADD command is syntactically correct?
Choose the syntactically valid Redis XADD command to add an entry with fields 'user'='alice' and 'score'='42' to stream 'game_scores'.
AXADD game_scores * user alice score 42
BXADD game_scores * user=alice score=42
CXADD game_scores user alice score 42 *
DXADD game_scores * (user alice) (score 42)
Attempts:
2 left
💡 Hint
The * must come immediately after the stream name, followed by field-value pairs without extra symbols.
optimization
advanced
2:00remaining
How to limit stream length efficiently with XADD?
You want to add entries to a Redis stream 'logs' but keep only the latest 1000 entries to save memory. Which XADD option achieves this efficiently?
AXADD logs MAXLEN=1000 * sensor temp
BXADD logs MAXLEN ~ 1000 * sensor temp
CXADD logs MAXLEN 1000~ * sensor temp
DXADD logs MAXLEN 1000 * sensor temp
Attempts:
2 left
💡 Hint
Using ~ after MAXLEN allows approximate trimming which is faster.
🔧 Debug
advanced
2:00remaining
Why does this XADD command cause an error?
Given the command:
XADD mystream 1657891234567-0 sensor 12
Why might this cause an error?
Redis
XADD mystream 1657891234567-0 sensor 12
AThe ID 1657891234567-0 already exists in the stream, causing a duplicate ID error
BThe field 'sensor' is missing a value
CThe ID format is invalid because it must be '*' for auto-generated IDs
DThe stream 'mystream' does not exist yet
Attempts:
2 left
💡 Hint
Manually specifying an ID that already exists causes an error.
🧠 Conceptual
expert
2:00remaining
What is the purpose of the '*' ID in XADD?
In Redis Streams, what does using '*' as the ID in the XADD command do?
AIt causes Redis to reject the command with a syntax error
BIt deletes the oldest entry in the stream before adding the new one
CIt tells Redis to auto-generate a unique ID based on the current timestamp and sequence number
DIt sets the ID of the new entry to zero
Attempts:
2 left
💡 Hint
The * is a special placeholder for IDs in Redis Streams.