Challenge - 5 Problems
ZREM Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of removing members with ZREM?
Given a sorted set
What will be the output of the command:
and what will be the new members in
myzset with members and scores:ZADD myzset 1 one 2 two 3 threeWhat will be the output of the command:
ZREM myzset two fourand what will be the new members in
myzset?Redis
ZADD myzset 1 one 2 two 3 three ZREM myzset two four ZRANGE myzset 0 -1 WITHSCORES
Attempts:
2 left
💡 Hint
ZREM returns the number of members actually removed. Only existing members count.
✗ Incorrect
The command ZREM myzset two four tries to remove 'two' and 'four'. 'two' exists and is removed, 'four' does not exist. So the output is 1. The remaining members are 'one' and 'three'.
🧠 Conceptual
intermediate1:30remaining
Understanding ZREM behavior with non-existing members
If you run
ZREM myzset a b c on a sorted set myzset that contains only x and y, what will be the output?Attempts:
2 left
💡 Hint
ZREM counts only members that were actually removed.
✗ Incorrect
Since none of 'a', 'b', or 'c' exist in the set, no members are removed, so the output is 0.
📝 Syntax
advanced1:30remaining
Which ZREM command syntax is correct?
Which of the following commands correctly removes members 'a' and 'b' from the sorted set 'myzset'?
Attempts:
2 left
💡 Hint
ZREM takes the key followed by one or more members separated by spaces.
✗ Incorrect
The correct syntax is to list members separated by spaces without brackets or quotes. Options A, B, and C are invalid syntax.
❓ optimization
advanced2:00remaining
Efficient removal of multiple members with ZREM
You want to remove 100 members from a sorted set in Redis. Which approach is the most efficient?
Attempts:
2 left
💡 Hint
Fewer calls to Redis server reduce overhead.
✗ Incorrect
Calling ZREM once with all members reduces network overhead and is more efficient than multiple calls.
🔧 Debug
expert2:30remaining
Why does this ZREM command fail?
You run the command:
but it does not remove any members, even though you expect members '1', '2', and '3' to be removed. What is the most likely reason?
ZREM myzset 1 2 3but it does not remove any members, even though you expect members '1', '2', and '3' to be removed. What is the most likely reason?
Attempts:
2 left
💡 Hint
Redis stores members as strings exactly as added.
✗ Incorrect
ZREM removes members by exact string match. If members were added as strings '1', '2', '3', passing numbers without quotes may cause no match.