>_ IzzyLab

Hands-on task

This task is step 4 of the course “Redis in production”

AOF that survives a restart

medium~20 min

The server stores sessions session:* (200 keys). RDB snapshots are disabled (save ""), so right now the data lives only in memory.

Enable the AOF log so that the setting survives a restart:

  • /etc/redis/redis.conf must contain appendonly yes and appendfsync everysec;
  • the sessions must not be lost;
  • after enabling it, write the key aof:check with the value survived;
  • restart Redis with service redis-server restart.

After the restart AOF must be on, and aof:check and all the sessions must still be there.

Open the config /etc/redis/redis.conf in the Editor tab — you can see what's in it now and what changed after your commands.

What you'll practise:
  • redis
  • AOF
  • appendonly
  • appendfsync
  • CONFIG REWRITE
  • persistence

Topic breakdown

AOF (append only file) is a log of all write commands: after a restart Redis replays it and restores the data. appendfsync controls how often the log is flushed to disk: always — on every write (safe and slow), everysec — once a second (you lose at most about a second, the standard choice), no — whenever the OS decides. Since Redis 7 AOF is multi-file: the appendonlydir directory holds a base file, incremental files and a manifest that ties them together. The classic mistake is to set appendonly yes only in the config and restart: on startup Redis reads the AOF, not the RDB, finds an empty log and starts with no data. The right order is to enable AOF at runtime (Redis itself writes the current dataset into the base file), wait for that to finish, and then persist the setting in the config.

What's checked

  1. AOF enabled in redis.conf
  2. Redis restarted
  3. AOF is active after the restart
  4. AOF directory with a manifest exists
  5. aof:check survived the restart
  6. sessions not lost

What it looks like