Redis persistence method-RDB-AOF

Redis persistence

  It is to save Redis data from memory to hard disk .
After persisting, a dump.rdb file will be generated in the folder of the current directory , which will save the data in your memory

1. What is RDB persistence ([***])

   RDB (Redis DataBase) specifies the frequency to persist Redis data , that is, at different points in time, the data stored in redis is snapshotted and stored on disks and other media.
   Redis supports this method by default . You don't need to do anything, Redis will automatically Stores the data in the memory to the hard disk, it will first write the data to a temporary file, wait for the end of the persistence process, and then replace the last persisted file with this temporary file.

默认频率如下:
     save 900 1   //900秒以内 ,如果至少有一个键的值发生变化, 则Redis自动持久化
     save 300 10  //300秒以内 ,如果至少有10个键的值发生变化, 则Redis自动持久化
     save 60 10000 //60秒以内 ,如果至少有10000个键的值发生变化, 则Redis自动持久化

You can modify redis.windows.confto change the frequency
Insert picture description here



2. AOF persistence (Redis does not support this method by default)

  AOF (Append Only File) persistence means that each operation is immediately persisted , that is, all the write instructions executed by redis are recorded. When redis is restarted next time, as long as these write instructions are executed again from front to back, you can Realizing data recovery
  is real-time (in the case of general data without any errors, it will be saved in the disk immediately after modification), this mechanism can bring higher data security, that is, data persistence
  Redis does not support this method by default

Let Redi support AOF persistence methods

  1. Modify redis.windows.confthe section 392 of the configuration file : appendonly no Change no to yes , if there is a write operation (ie set, etc.), redis will be appended to the end of the AOF file.

Insert picture description here

  1. Restart the server and
    reopen the start.bat script file

  2. Redis will automatically generate a file in the current folder: appendonly.aof file, the appearance of appendonly.aof file means that AOF is turned on
    Insert picture description here

  3. By default, AOF is persisted once per second.
    By default, appendfsync everysec . In this case, even if there is an exception, it will only lose data within 1 second. If you want higher requirements, you can change to always

Keyword Persistence timing (value) description
appendfsync always Every time an update command is executed, it will be persisted once
appendfsync everysec Persistence every second by default
appendfsync no Endurance

3. Summary

  • Both RDB and AOF methods can be used at the same time, but in this case, after restarting redis, the AOF method will be preferred for data recovery, because the AOF method has a higher data recovery integrity.
  • If the data is very sensitive/important and requires very high data integrity, then use the AOF method, because if Redis fails, there may be a long period of data loss (the default is 900 seconds, which is 5 minutes of data loss) . With AOF, even if there is a failure, the data within 1 second will be lost at most (the default persistence is once per second, if the requirement is higher, it can be changed to always, and the update command will be persisted)
  • If there is no need for data persistence, you can also turn off RDB and AOF methods, redis will become a pure memory database

Guess you like

Origin blog.csdn.net/qq_40542534/article/details/108721914