Challenge - 5 Problems
ZADD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the result of this ZADD command?
Given an empty sorted set named 'players', what will be the output after running this command?
What does the command return?
ZADD players 10 "Alice" 20 "Bob" 15 "Charlie"What does the command return?
Redis
ZADD players 10 "Alice" 20 "Bob" 15 "Charlie"
Attempts:
2 left
💡 Hint
ZADD returns the number of new elements added to the sorted set.
✗ Incorrect
Since the sorted set 'players' was empty, all three members are new and added. So, the command returns 3.
📝 Syntax
intermediate1:30remaining
Which ZADD command syntax is correct?
Which of the following ZADD commands is syntactically correct to add two members with scores to a sorted set named 'scores'?
Attempts:
2 left
💡 Hint
The syntax is: ZADD key score1 member1 [score2 member2 ...]
✗ Incorrect
Option A follows the correct syntax: score followed by member, repeated for each pair. Option A swaps score and member. Option A misses quotes around members (optional but recommended). Option A uses commas which are invalid in Redis commands.
❓ optimization
advanced2:00remaining
Optimizing multiple ZADD operations
You want to add 1000 members with scores to a sorted set 'rankings'. Which approach is more efficient?
Attempts:
2 left
💡 Hint
Minimize the number of commands sent to Redis for better performance.
✗ Incorrect
Sending one ZADD command with all members reduces network overhead and is more efficient than multiple commands.
🔧 Debug
advanced1:30remaining
Why does this ZADD command fail?
You run this command:
and get an error. What is the cause?
ZADD leaderboard 50 "player1" 40and get an error. What is the cause?
Attempts:
2 left
💡 Hint
Each score must be followed by a member name.
✗ Incorrect
The command provides a score (40) without a corresponding member name, causing a syntax error.
🧠 Conceptual
expert2:00remaining
What happens when adding a member with an existing name but different score?
Consider a sorted set 'tasks' with member 'task1' having score 5. What will be the result of:
What does Redis do?
ZADD tasks 10 "task1"What does Redis do?
Attempts:
2 left
💡 Hint
ZADD updates the score if the member exists.
✗ Incorrect
Redis updates the score of existing members and returns 0 because no new member was added.