Redis Persistence

Redis is a caching server but it offers some ways to persist the database, so the db can be recovered when the service shut down unexpectingly.

There are two ways to dump the data:

  • RDB persistence performs point-in-time snapshots of your database at specified interval.
  • AOF persistence logs every write operation received by the server.

It is possible to combine RDB and AOF in single instance. If both are on, redis will using AOF file to reconstruct the original dataset since it is guaranteed to be the most complete.

RDB

  • RDB file are perfect for backups.
  • RDB is very good for disaster, being a compact file that can be transfered to remote server.
  • RDB maximizes Redis perforamce since the only work that the parent process need to do in order to persist is forking a child that will do the rest.
  • RDB allow faster restart with big dataset compare to AOF file.

How to configure RDB?

By default Redis save snapshots of dataset on disk, in binary file named dump.rdb.

We can configure redis to have it saved the dataset every N second if there are M keys change in the database.

We can trigger redis to dump dataset by 'SAVE' or 'BGSAVE' commands.

For example, command SAVE 600 1000 means Redis will dump database in every 600 seconds if at least 1000 keys change.

AOF (Append-only File)

AOF is another way to persist redis dataset, which append the key to binary file every time it receive a write command.

We can use command appendonly yes to turn AOF on.

REFERENCE:

https://redis.io/topics/persistence

你可能感兴趣的:(Redis Persistence)