Premier League Predictor: FastAPI & Redis — Chapter 2, Exercise 2 ===================================================================== TASK Run two real SADD calls against the same season:1:teams set -- the first adding two genuinely new team IDs, the second adding one team ID already in the set alongside one genuinely new one. Report SADD's own real return value for each call, and explain what that return value is actually counting. SOLUTION Running the two real calls in sequence against a freshly cleared set: add1 = await r.sadd("season:1:teams", 1, 2) # add1 -> 2 add2 = await r.sadd("season:1:teams", 2, 3) # add2 -> 1 members = await r.smembers("season:1:teams") # members -> {'1', '2', '3'} The first call adds team 1 and team 2, both genuinely new to the set, and returns 2 -- both were counted. The second call is given team 2 (already present from the first call) and team 3 (genuinely new). Even though two arguments were passed to the second SADD call, it returns 1, not 2. SADD's own real return value is not "how many arguments were passed" -- it's specifically "how many of the given members were not already present, and therefore genuinely newly added." Team 2 was silently ignored on the second call, since a Set can never contain the same member twice by definition, and SADD's own return value reflects that: it only counts the members that actually changed the set's own contents. The final SMEMBERS result, {'1', '2', '3'}, confirms this directly -- team 2 appears exactly once, not twice, despite being passed to SADD in two separate calls. This return value is genuinely useful in real application code beyond just curiosity -- checking whether SADD returned 0 is a real, correct way to detect "this exact membership already existed, nothing changed" without needing a separate SISMEMBER check beforehand. WHY THIS WORKS AS AN ANSWER ---------------------------- It reports the real return values from both calls, correctly identifies that SADD counts genuinely new insertions rather than total arguments, and explains the real, practical use of that distinction -- detecting whether a membership operation actually changed anything without a separate existence check.