Get the App
SLTechnology News&Howtos  ›  Database  › 

Persistence of Redis

Shulou Source: shulou.com Published: 2022-06-01 05:23:28 09月15日 Update

Redis is an in-memory database that supports persistence, which means that redis needs to frequently synchronize the data in memory to the hard disk to ensure persistence. Redis supports two persistence methods:

1. Snapshotting (snapshot) is also the default method. Writes the data in memory to the file as a snapshot. The default file name is dump.rdb.

[root@D2-LZY245 redis-4.0.1] # grep ^ save redis.conf

Save 900 1

Save 300 10

Save 60 10000

2. Append-only file (aof). Because snapshots are done at regular intervals, if redis accidentally down, all modifications since the last snapshot will be lost. Aof is more persistent than snapshots because when using aof, redis appends every write command received to the file through the write function, and when redis restarts, it rebuilds the contents of the entire database in memory by re-executing the write commands saved in the file.

Because os caches changes made by write in the kernel, everything may not be written to disk immediately. In this way, it is still possible to lose some of the changes in aof persistence. You can tell redis through the configuration file when you want to force OS to write to disk through the fsync function.

# The name of the appendonly file (default: "appendonly.aof")

Appendfilename "appendonly.aof"

# always: fsync after every write to the append only log. Slow, Safest.

# appendfsync always

Appendfsync everysec

# appendfsync no

Tags: Mode snapshot file memory data function command database disk support accident that is content kernel can be passed persistence file name timing time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei Shulou Information MySQL OPPO Reno