Recall & Review
beginner
What does the Redis command
ZINCRBY do?It increases the score of a member in a sorted set by a given amount. If the member does not exist, it is added with the increment as its score.
Click to reveal answer
beginner
How do you increase the score of member 'player1' by 10 in a sorted set 'game_scores'?
Use the command:
ZINCRBY game_scores 10 player1.Click to reveal answer
beginner
What happens if you use
ZINCRBY on a member that does not exist in the sorted set?The member is added to the sorted set with the score equal to the increment value.
Click to reveal answer
intermediate
Can
ZINCRBY decrease a member's score? How?Yes, by using a negative increment value. For example,
ZINCRBY game_scores -5 player1 decreases player1's score by 5.Click to reveal answer
beginner
What type of data structure does
ZINCRBY work with in Redis?It works with sorted sets, which store members ordered by their scores.
Click to reveal answer
What does the Redis command
ZINCRBY myset 3 member1 do?✗ Incorrect
ZINCRBY increases the score of the member by the given increment or adds it with that score if it doesn't exist.
If you run
ZINCRBY leaderboard -2 player42, what happens?✗ Incorrect
ZINCRBY accepts negative increments to decrease a member's score.
Which Redis data type is required to use
ZINCRBY?✗ Incorrect
ZINCRBY works only with sorted sets.
What will
ZINCRBY scores 5 newplayer do if 'newplayer' is not in 'scores'?✗ Incorrect
If the member does not exist, ZINCRBY adds it with the increment as its score.
What does the return value of
ZINCRBY represent?✗ Incorrect
ZINCRBY returns the updated score of the member.
Explain how the Redis command ZINCRBY updates scores in a sorted set.
Think about how scores change and what happens if the member is new.
You got /4 concepts.
Describe a real-life example where you might use ZINCRBY in a Redis sorted set.
Imagine a game where players earn points over time.
You got /4 concepts.