0
0
Redisquery~5 mins

ZINCRBY for score updates in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ARemoves 'member1' from 'myset'
BAdds 3 to the score of 'member1' in 'myset', or adds 'member1' with score 3 if not present
CSets the score of 'member1' to 3 in 'myset' regardless of previous score
DReturns the current score of 'member1' in 'myset'
If you run ZINCRBY leaderboard -2 player42, what happens?
AThe score of 'player42' increases by 2
B'player42' is removed from 'leaderboard'
CAn error occurs because increment cannot be negative
DThe score of 'player42' decreases by 2
Which Redis data type is required to use ZINCRBY?
AList
BHash
CSorted Set
DString
What will ZINCRBY scores 5 newplayer do if 'newplayer' is not in 'scores'?
AAdd 'newplayer' with score 5
BAdd 'newplayer' with score 0
CDo nothing
DReturn an error
What does the return value of ZINCRBY represent?
AThe new score of the member after increment
BThe old score before increment
CThe total number of members in the sorted set
DThe rank of the member in the sorted set
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.