Premier League Predictor: FastAPI & Redis — Chapter 8, Exercise 1 ================================================================= TASK Reproduce the mixed-unit bug with the chapter's season totals (user 180, expert 340, AI 320, guest 32665), report the order, then convert everything to hundredths and report the corrected order and scores. SOLUTION Mixed units (guest already in hundredths, the others in whole points): await r.zadd("mixed", {"user": 180, "expert": 340, "ai": 320, "guest": 32665}) await r.zrevrange("mixed", 0, -1) -> ['guest', 'expert', 'ai', 'user'] The guest average is 326.65 points, but 32665 is a far bigger number than 340, so it ranks first. Common unit (multiply the whole-point sources by 100): await r.zadd("fixed", {"user": 18000, "expert": 34000, "ai": 32000, "guest": 32665}) await r.zrevrange("fixed", 0, -1, withscores=True) -> [('expert', 34000.0), ('guest', 32665.0), ('ai', 32000.0), ('user', 18000.0)] The expert is first, then the guest average, the AI, the user. Redis stores only numbers. It cannot know that one member's score is in a different unit, so the only defence is a naming and conversion discipline in the code that writes the scores - which is why the field is called guest_avg_x100. WHY THIS WORKS AS AN ANSWER ---------------------------- It reproduces the wrong order with real data, then shows the corrected order and the actual scores, and names why Redis cannot catch it.