The persistence mechanisms of Redis include the RBD and AoF two, which are described in this article for each of these two persistence approaches.
the strategy of the RDB mechanism
RDB persistence refers to the way in which in-memory data and operations are saved to the Redis Bin directory at a specified time interval by default named Dump.rdb files, which can be configured to set automatic snapshot persistence, we can configure the time that Redis takes to snapshot in n seconds, and if this time node is exceeded, the snapshot operation will be performed automatically. Although this method is convenient and fast, but can not guarantee the absolute security of the data, if the server in the non-backup time span of failure, can not do real-time preservation of the current state, resulting in data loss. And every time you save an RDB file, Redis needs to fork () out a child process to perform the specific persistence work and consume a large resource.
strategy of AOF mechanism
The AOF persistence of Redis is appended to the file by the Write function on each command (the default is APPENDONLY.AOF), but because the operating system uses a cache to write to the file to improve write efficiency, or there may be data loss due to a sudden server failure, we can tell Redis our time interval for synchronizing data through a configuration file (the default interval is synchronous once per second)
AppendOnly Yes //enable AOF Persistence
# Appendfsync always//force write to disk as soon as you receive the Write command, slowest, but guaranteed full persistence,
deprecated Appendfsync everysec //force write to disk once per second, a good compromise in performance and persistence, recommended
# Appendfsync no //full OS-dependent, best performance, no guarantee of durability