Predict the output
What does the leaderboard query print?
import redis
r = redis.Redis(decode_responses=True)
r.zadd("board", {"ana": 30, "ben": 50, "cy": 40})
r.zincrby("board", 25, "ana")
print(r.zrevrange("board", 0, 1, withscores=True))Hint 1 of 1
What does ZINCRBY do to ana?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A [('ana', 55.0), ('ben', 50.0)]
Correct. ana goes from 30 to 55 and moves to the top; scores come back as floats.
ZINCRBY adds 25 to ana's score, making it 55. Reading the sorted set from highest to lowest gives the top two, and the Python client returns scores as floats.
Why not the others?
- B
[('ben', 50.0), ('cy', 40.0)]. That ignores the ZINCRBY. - C
[('ana', 55), ('ben', 50)]. Sorted-set scores are returned as floats. - D
['ana', 'ben']. withscores=True returns pairs.