0
0
Redisquery~20 mins

ZADD for adding scored members in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ZADD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1: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?

ZADD players 10 "Alice" 20 "Bob" 15 "Charlie"

What does the command return?
Redis
ZADD players 10 "Alice" 20 "Bob" 15 "Charlie"
A1
B0
C3
DError: wrong number of arguments
Attempts:
2 left
💡 Hint
ZADD returns the number of new elements added to the sorted set.
📝 Syntax
intermediate
1: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'?
AZADD scores 100 "John" 200 "Jane"
BZADD scores 100, "John", 200, "Jane"
CZADD scores 100 John 200 Jane
DZADD scores "John" 100 "Jane" 200
Attempts:
2 left
💡 Hint
The syntax is: ZADD key score1 member1 [score2 member2 ...]
optimization
advanced
2:00remaining
Optimizing multiple ZADD operations
You want to add 1000 members with scores to a sorted set 'rankings'. Which approach is more efficient?
AUse a single ZADD command with all 1000 score-member pairs.
BRun 1000 separate ZADD commands, each adding one member.
CUse 10 ZADD commands, each adding 100 members.
DAdd members one by one using ZINCRBY with score increments.
Attempts:
2 left
💡 Hint
Minimize the number of commands sent to Redis for better performance.
🔧 Debug
advanced
1:30remaining
Why does this ZADD command fail?
You run this command:

ZADD leaderboard 50 "player1" 40

and get an error. What is the cause?
AScore must be an integer, 50 is invalid
BMissing member name after score 40
CQuotes around member names are not allowed
DLeaderboard key does not exist
Attempts:
2 left
💡 Hint
Each score must be followed by a member name.
🧠 Conceptual
expert
2: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:

ZADD tasks 10 "task1"

What does Redis do?
AReturns an error because 'task1' already exists
BAdds a new member 'task1' with score 10 and returns 1
CIgnores the command and returns 0
DUpdates 'task1' score to 10 and returns 0
Attempts:
2 left
💡 Hint
ZADD updates the score if the member exists.