0
0
Redisquery~20 mins

XLEN for stream length in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Stream Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1: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
A0
B3
CAn error because XLEN requires a key type check
DThe ID of the last entry in the stream
Attempts:
2 left
💡 Hint
XLEN returns the number of entries in the stream.
query_result
intermediate
1: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
Anull
BAn error indicating the key does not exist
C0
D-1
Attempts:
2 left
💡 Hint
XLEN returns zero if the stream key does not exist.
📝 Syntax
advanced
1: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?
AXLEN -key events
BXLEN(events)
CXLEN events STREAM
DXLEN events
Attempts:
2 left
💡 Hint
XLEN takes exactly one argument: the stream key name.
🔧 Debug
advanced
2: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
Amylist is a list, not a stream, so XLEN cannot be used
BThe Redis server version does not support XLEN
CXLEN requires a second argument specifying the type
Dmylist is empty, so XLEN returns an error
Attempts:
2 left
💡 Hint
XLEN only works on stream data types.
🧠 Conceptual
expert
2: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?
AXLEN returns approximately 1000, but exact count may vary due to approximate trimming
BXLEN always returns exactly 1000 after trimming
CXLEN returns the total number of entries ever added to the stream
DXLEN returns zero if trimming is enabled
Attempts:
2 left
💡 Hint
Approximate trimming means the stream length is close to the max length but not exact.