0
0
Redisquery~20 mins

ZINCRBY for score updates in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ZINCRBY Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1:30remaining
What is the new score of 'player1' after this command?
Given a sorted set 'game_scores' with 'player1' having a score of 50, what will be the score of 'player1' after running:

ZINCRBY game_scores 20 player1
Redis
ZINCRBY game_scores 20 player1
A70
B20
C50
DError: member not found
Attempts:
2 left
💡 Hint
ZINCRBY adds the increment to the current score of the member.
query_result
intermediate
1:30remaining
What happens if the member does not exist?
What will be the result of running:

ZINCRBY game_scores 15 playerX

when 'playerX' is not in the sorted set 'game_scores'?
Redis
ZINCRBY game_scores 15 playerX
A0
BError: member not found
CNo change, returns nil
D15
Attempts:
2 left
💡 Hint
ZINCRBY adds the member if it does not exist, starting with the increment as score.
📝 Syntax
advanced
1:30remaining
Which command syntax is correct to increase 'player2' score by 10?
Choose the correct Redis command to increase the score of 'player2' by 10 in the sorted set 'game_scores'.
AZINCRBY game_scores player2 10
BZINCRBY 10 game_scores player2
CZINCRBY game_scores 10 player2
DZINCRBY player2 game_scores 10
Attempts:
2 left
💡 Hint
The syntax is ZINCRBY key increment member.
optimization
advanced
2:00remaining
How to efficiently update multiple player scores?
You want to increase scores of multiple players in 'game_scores' by different amounts. Which approach is best for performance?
AUse a Redis pipeline to send multiple ZINCRBY commands at once.
BRun multiple ZINCRBY commands one by one.
CUse ZINCRBY with multiple members in one command.
DDelete and recreate the sorted set with updated scores.
Attempts:
2 left
💡 Hint
Pipelining reduces network round trips.
🧠 Conceptual
expert
2:00remaining
What is the effect of using a negative increment with ZINCRBY?
If you run:

ZINCRBY game_scores -30 player3

and 'player3' has a current score of 25, what will be the new score and what happens if the score becomes negative?
AMember is removed if score goes below zero.
BNew score is -5; Redis allows negative scores in sorted sets.
CError; Redis does not allow negative increments.
DNew score is 0; Redis sets negative scores to zero automatically.
Attempts:
2 left
💡 Hint
Redis sorted sets can have negative scores.