Challenge - 5 Problems
Redis Stream Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of XLEN on a non-empty stream?
Given a Redis stream named
mystream with 3 entries, what will the command XLEN mystream return?Redis
XADD mystream * field1 value1 XADD mystream * field2 value2 XADD mystream * field3 value3 XLEN mystream
Attempts:
2 left
💡 Hint
XLEN returns the number of entries in the stream.
✗ Incorrect
XLEN returns the count of entries in the stream. Since 3 entries were added, XLEN mystream returns 3.
❓ query_result
intermediate1:30remaining
What does XLEN return for a non-existent stream?
What will the command
XLEN mystream return if mystream does not exist in Redis?Redis
XLEN mystream
Attempts:
2 left
💡 Hint
XLEN returns zero if the stream key does not exist.
✗ Incorrect
If the stream key does not exist, XLEN returns 0 because there are no entries.
📝 Syntax
advanced1:30remaining
Which XLEN command syntax is correct?
Which of the following Redis commands correctly uses XLEN to get the length of a stream named
events?Attempts:
2 left
💡 Hint
XLEN takes exactly one argument: the stream key name.
✗ Incorrect
The correct syntax is
XLEN key. Options A, B, and C are invalid Redis command syntaxes.🔧 Debug
advanced2:00remaining
Why does XLEN return an error on this key?
You run
XLEN mylist but get an error: WRONGTYPE Operation against a key holding the wrong kind of value. What is the most likely cause?Redis
RPUSH mylist a b c XLEN mylist
Attempts:
2 left
💡 Hint
XLEN only works on stream data types.
✗ Incorrect
XLEN only works on streams. Since mylist is a list, Redis returns a WRONGTYPE error.
🧠 Conceptual
expert2:30remaining
How does XLEN behave under heavy stream trimming?
If a Redis stream
logs is trimmed frequently with XTRIM logs MAXLEN ~ 1000, what can be said about the value returned by XLEN logs?Attempts:
2 left
💡 Hint
Approximate trimming means the stream length is close to the max length but not exact.
✗ Incorrect
Using
~ in XTRIM causes approximate trimming, so XLEN returns a length close to but not exactly 1000.