Premier League Predictor: FastAPI & Redis — Chapter 7, Exercise 3 ================================================================= TASK Enter a 2-0 result, then correct it to 0-1. Compare the resulting table and stats against entering 0-1 on a fresh table, and report exactly what matches and what differs. SOLUTION Fixture 1: team 1 (home) v team 2 (away), 4-team table. After entering 2-0: table order: 001, 003, 004, 002 team 1 stats: played 1, gf 2, ga 0, won 1 team 2 stats: played 1, gf 0, ga 2, lost 1 After correcting to 0-1: table: 002 (-3501001), 003 (-500000), 004 (-500000), 001 (-499000) team 1: {'played': '1', 'gf': '0', 'ga': '1', 'won': '0', 'lost': '1'} team 2: {'played': '1', 'gf': '1', 'ga': '0', 'lost': '0', 'won': '1'} Entering 0-1 on a fresh table: table: 002 (-3501001), 003 (-500000), 004 (-500000), 001 (-499000) team 1: {'played': '1', 'gf': '0', 'ga': '1', 'lost': '1'} team 2: {'played': '1', 'gf': '1', 'ga': '0', 'won': '1'} What matches: the sorted-set order and every score, and every stat that is non-zero. What differs: the stats hashes are not identical. In the corrected run team 1 has 'won': '0' and team 2 has 'lost': '0'; in the fresh run those fields do not exist. HINCRBY -1 brings a field to 0 but leaves it in place, while a fresh run never created it. Consequence: code that reads stats must treat a missing field as 0, for example int(stats.get("won", 0)). Comparing two stats hashes for equality is the wrong test of "same table"; compare the values with defaults, or compare the sorted set. WHY THIS WORKS AS AN ANSWER ---------------------------- It separates what the correction gets right (scores, order, all live numbers) from a representational difference that does not change any table value, and turns that difference into a concrete rule for readers.