Given the following Redis commands executed in order:
ZINCRBY scores 10 alice
ZINCRBY scores 5 bob
ZINCRBY scores -3 alice
ZINCRBY scores 2 charlie
What is the score of alice after these commands?
medium
A. 7
B. 10
C. 12
D. -3
Solution
Step 1: Calculate alice's score changes
First increment: +10, then decrement: -3, total = 10 - 3 = 7.
Step 2: Confirm final score
Other members' scores do not affect alice's score.
Final Answer:
7 -> Option A
Quick Check:
10 - 3 = 7 [OK]
Hint: Add increments for the same member to get final score [OK]
Common Mistakes:
Ignoring negative increments
Adding scores of other members
Using only the first increment
4.
What is wrong with this Redis command to increase user2's score by 4 in sorted set game_scores?
ZINCRBY game_scores user2 4
medium
A. The increment value must be negative.
B. The key name is missing.
C. The command should be ZADD instead of ZINCRBY.
D. The increment and member arguments are swapped.
Solution
Step 1: Check argument order for ZINCRBY
ZINCRBY syntax is: ZINCRBY key increment member. Here, 'user2' and '4' are swapped.
Step 2: Identify the error
The command should be: ZINCRBY game_scores 4 user2.
Final Answer:
The increment and member arguments are swapped. -> Option D
Quick Check:
Order must be key, increment, member [OK]
Hint: Increment always comes before member in ZINCRBY [OK]
Common Mistakes:
Swapping increment and member
Using ZADD instead of ZINCRBY for increment
Thinking increment must be negative
5.
You have a sorted set ranking with members and scores:
"alice" 15
"bob" 20
"carol" 10
You want to increase carol's score by 12 and decrease bob's score by 5 using Redis commands. Which sequence of commands correctly updates the scores?
hard
A. ZADD ranking 22 carol
ZADD ranking 15 bob
B. ZINCRBY ranking carol 12
ZINCRBY ranking bob -5
C. ZINCRBY ranking 12 carol
ZINCRBY ranking -5 bob
D. ZINCRBY ranking 5 carol
ZINCRBY ranking -12 bob
Solution
Step 1: Apply correct ZINCRBY syntax for increments
To increase carol's score by 12: ZINCRBY ranking 12 carol.
Step 2: Apply correct ZINCRBY syntax for decrement
To decrease bob's score by 5: ZINCRBY ranking -5 bob.
Step 3: Verify other options
ZINCRBY ranking carol 12
ZINCRBY ranking bob -5 swaps increment and member, ZADD ranking 22 carol
ZADD ranking 15 bob uses ZADD which replaces scores, ZINCRBY ranking 5 carol
ZINCRBY ranking -12 bob uses wrong increments.
Final Answer:
ZINCRBY ranking 12 carol
ZINCRBY ranking -5 bob -> Option C
Quick Check:
Use ZINCRBY with positive and negative increments [OK]
Hint: Use positive or negative increments with ZINCRBY to adjust scores [OK]
Common Mistakes:
Swapping member and increment arguments
Using ZADD which overwrites scores instead of incrementing
Using wrong increment values
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.