4. You run the command XTRIM mystream MAXLEN ~1000 but notice the stream still has over 2000 entries. What is the most likely reason?
medium
A. The command syntax is incorrect and was ignored.
B. The approximate trim (~) allows the stream to exceed the limit temporarily.
C. XTRIM only works on empty streams.
D. The stream key name is case-sensitive and was misspelled.
Solution
Step 1: Understand approximate trimming behavior
Using the tilde (~) means trimming is approximate and may allow the stream to temporarily exceed the limit.
Step 2: Eliminate other causes
Syntax is correct, XTRIM works on non-empty streams, and key name issues would cause errors, not approximate trimming behavior.
Final Answer:
The approximate trim (~) allows the stream to exceed the limit temporarily. -> Option B
Quick Check:
Approximate trim = possible temporary size excess [OK]
Hint: Approximate trim (~) may exceed limit briefly [OK]
Common Mistakes:
Assuming syntax error caused no trimming
Thinking XTRIM only works on empty streams
Ignoring approximate trimming behavior
5. You want to keep a Redis stream events capped at 500 entries but want to improve trimming speed by allowing approximate trimming. Which command should you use?
hard
A. XTRIM events MAXLEN = 500
B. XTRIM events MAXLEN 500
C. XTRIM events MINLEN ~ 500
D. XTRIM events MAXLEN ~500
Solution
Step 1: Identify approximate trimming syntax
Approximate trimming uses the tilde (~) before the number with MAXLEN.
Step 2: Choose correct command
XTRIM events MAXLEN ~500 caps the stream at about 500 entries with faster trimming.
Final Answer:
XTRIM events MAXLEN ~500 -> Option D
Quick Check:
Approximate trim = MAXLEN ~ number [OK]
Hint: Use MAXLEN ~ number for fast approximate trimming [OK]
Common Mistakes:
Using MINLEN instead of MAXLEN
Using equals sign (=) which is invalid
Omitting the tilde (~) for approximate trimming
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.