0
0
Redisquery~20 mins

XTRIM for stream capping in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stream Capping Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the effect of this XTRIM command?
Given a Redis stream named mystream with 1000 entries, what will be the number of entries after running this command?

XTRIM mystream MAXLEN 100
Redis
XTRIM mystream MAXLEN 100
AThe stream will have 1000 entries, no change occurs.
BThe stream will have exactly 900 entries, the newest entries removed.
CThe stream will have exactly 100 entries, the oldest entries removed.
DThe command will cause an error because MAXLEN requires a minimum of 1000.
Attempts:
2 left
💡 Hint
MAXLEN trims the stream to keep only the newest entries up to the specified count.
🧠 Conceptual
intermediate
2:00remaining
What does the ~ (approximate) flag do in XTRIM?
Consider the command:
XTRIM mystream MAXLEN ~ 100
What is the purpose of the ~ flag in this context?
Redis
XTRIM mystream MAXLEN ~ 100
AIt forces Redis to trim exactly 100 entries, no approximation allowed.
BIt allows Redis to trim the stream approximately to 100 entries for better performance.
CIt disables trimming and only returns the current length of the stream.
DIt causes an error because ~ is not a valid flag for XTRIM.
Attempts:
2 left
💡 Hint
The ~ flag is used to improve performance by allowing approximate trimming.
📝 Syntax
advanced
2:00remaining
Which XTRIM command syntax is correct to cap a stream to 500 entries approximately?
Choose the syntactically correct Redis command to trim mystream to approximately 500 entries.
AXTRIM mystream MAXLEN ~ 500
BXTRIM mystream MAXLEN 500 ~
CXTRIM mystream MAXLEN ~500
DXTRIM mystream MAXLEN=~ 500
Attempts:
2 left
💡 Hint
The approximate flag ~ must come immediately after MAXLEN.
optimization
advanced
2:00remaining
Why use approximate trimming (~) instead of exact trimming in XTRIM?
What is the main advantage of using XTRIM mystream MAXLEN ~ 1000 over XTRIM mystream MAXLEN 1000?
AApproximate trimming disables trimming and only returns the stream length.
BApproximate trimming guarantees the stream length is exactly 1000 entries.
CApproximate trimming causes Redis to trim entries randomly.
DApproximate trimming reduces CPU usage by allowing Redis to trim in batches.
Attempts:
2 left
💡 Hint
Think about performance and resource usage when trimming large streams.
🔧 Debug
expert
2:00remaining
What error occurs with this XTRIM command?
Given the command:
XTRIM mystream MAXLEN -100
What will Redis respond?
Redis
XTRIM mystream MAXLEN -100
AAn error: 'ERR The MAXLEN argument must be a positive integer'
BThe stream is trimmed to 100 entries ignoring the negative sign.
CThe stream is cleared completely because negative length means zero entries.
DNo error, Redis treats -100 as a large positive number.
Attempts:
2 left
💡 Hint
MAXLEN must be a positive number; negative values are invalid.