Premier League Predictor: FastAPI & Redis — Chapter 1, Exercise 2 ===================================================================== TASK Reproduce this chapter's own tie-breaking warning with real code: add three teams to a sorted set with the exact same score, read them back with ZRANGE in descending order, and explain the real order you get by working out what Redis's own tie-breaking rule (ascending by member name) would produce once the whole set is reversed for a descending read. SOLUTION Adding three teams to a real sorted set, all tied on the exact same real points total: await r.zadd("demo:tiebreak", {"Zeta United": 50, "Alpha FC": 50, "Middleton": 50}) result = await r.zrange("demo:tiebreak", 0, -1, desc=True, withscores=True) produces this real, observed order: [('Zeta United', 50.0), ('Middleton', 50.0), ('Alpha FC', 50.0)] Working out why this is the correct expected order: Redis's own real tie-breaking rule is to order tied members in ASCENDING lexicographic order by member name. Sorted purely alphabetically, ascending, the three team names would read: Alpha FC, Middleton, Zeta United That's the real internal order Redis maintains for these three tied members. Requesting the set with desc=True doesn't re-sort anything by a different rule -- it reverses the ENTIRE ordered set, tie-broken members included, exactly as if the whole list were read backwards. Reversing "Alpha FC, Middleton, Zeta United" gives: Zeta United, Middleton, Alpha FC which matches the real, observed result exactly. The genuinely important part for this course's own real league-table use case: that ordering has nothing to do with anything a real Premier League table would want to use as a tiebreaker. Zeta United outranking Alpha FC here isn't because Zeta United has a better goal difference, a better head-to-head record, or anything meaningful at all -- it's purely an artifact of which letter each name happens to start with, and which direction the set happens to be read in. Any real tiebreaker logic (goal difference, as the chapter's own warning names directly) has to be computed and applied separately -- Redis's own sorted set gives an ordering for free, but not the specific ordering this domain actually needs when scores tie. WHY THIS WORKS AS AN ANSWER ---------------------------- It reproduces the real tied-score scenario with actual code, correctly derives the observed reversed order from Redis's own real ascending lexicographic tie-breaking rule combined with the desc=True reversal, and explains why that real ordering is meaningless for a genuine Premier League tiebreaker, setting up the real need for goal difference addressed later in the course.