Premier League Predictor: FastAPI & Redis — Chapter 9, Exercise 3 ================================================================= TASK Start a default Redis container and one with the append-only file and fsync always, write two keys to each, kill both with docker kill, restart them and count the keys. Then repeat the default one with docker stop. Report all three results and say which restart behaviour to rely on for hand-entered fixtures. SOLUTION docker run -d --name plredis -p 6399:6379 redis:latest docker run -d --name plaof -p 6398:6379 redis:latest \ redis-server --appendonly yes --appendfsync always Config of the default container (CONFIG GET): save = 3600 1 300 100 60 10000 appendonly = no appendfsync = everysec Both containers: SET season:current_id 7, and HSET fixture:1 with home_score 2, away_score 1 (DBSIZE = 2). docker kill plredis plaof ; docker start plredis plaof default: DBSIZE 0 season:current_id -> None appendonly always: DBSIZE 2 season:current_id -> '7' Default container again, written to and then stopped gracefully: docker stop plredis ; docker start plredis default: DBSIZE 2 season:current_id -> '7' Results: - default + hard kill -> everything lost (no snapshot had been taken yet) - default + graceful stop -> kept (shutdown writes a snapshot) - AOF + fsync always + hard kill -> kept Which to rely on: the fixtures and predictions in this app are typed in by hand and cannot be recomputed from anything else, so a hard kill must not lose them. That points to the append-only file (accepting the cost of an fsync on each write, or choosing a setting between the two and understanding the window it leaves), not to the defaults. The table and leaderboard are derived data, so losing them is recoverable; losing fixtures is not. WHY THIS WORKS AS AN ANSWER ---------------------------- It reproduces all three behaviours with real restarts, states exactly what was and was not tested, and ties the choice to which data is source data and which can be rebuilt.