Premier League Predictor: FastAPI & Redis — Chapter 6, Exercise 1 ================================================================= TASK Submit the identical 40-point score for the same source twice, once through a plain HINCRBY total and once through the APPLY_POINTS Lua script. Report both totals and explain what each design remembers that the other doesn't. SOLUTION Plain increment: await r.hincrby("naive", "user", 40) await r.hincrby("naive", "user", 40) -> {'user': '80'} Delta script (points hash + totals hash), called twice with user = 40: await apply(keys=["fixture:1:points", "totals"], args=["user", "40"]) await apply(keys=["fixture:1:points", "totals"], args=["user", "40"]) -> {'user': '40'} The plain counter double-counts: it has no record of what it already added for this fixture, so every call is treated as new points. The delta design keeps each fixture's own points in fixture:{id}:points, so the second call computes new (40) minus old (40) = 0 and the total does not move. What each remembers: the plain total remembers only a running sum. The delta design also remembers the contribution each fixture made to that sum, which is exactly the information needed to undo or replace it. WHY THIS WORKS AS AN ANSWER ---------------------------- It runs both designs on the same input, shows the different totals, and names the actual difference — per-fixture state — instead of just saying one is "safer".