APPENDIX · P6 · REDIS · FOR SLIDE 16
← Back to Slide 16
P6. Tie, nil, and replay ZINCRBY
DEL lesson03:tie
ZADD lesson03:tie 1720 player:1042 1720 player:2001
ZRANGE lesson03:tie 0 9 REV WITHSCORES
ZREVRANK lesson03:tie player:1042
ZREVRANK lesson03:tie player:missing
ZINCRBY lesson03:tie 25 player:1042
ZINCRBY lesson03:tie 25 player:1042
ZADD lesson03:tie not-a-score player:x
What the result should be
(integer) 0 or 1
(integer) 2
1) "player:2001" 2) "1720"
3) "player:1042" 4) "1720"
(integer) 1 // position = 1 + 1
(nil) // check up to +1
"1745"
"1770" // repeat = another +25
(error) … not a valid float
Tie
nil
Not impotent
Equal score: sorted by member bytes; with REV, the order is reversed. “2” > “1”.
Absent player: rank nil. You cannot add one.
A repeat submission of the match result counts for points twice.
"First to reach — highest" Redis won't do this on its own. Store `achieved_at` and sort in SQL (P7), rather than hiding the time in the `score` fraction.