Redis provides two methods for persistence, one is RDB persistence (the principle is to periodically dump Reids' database records in memory to RDB persistence on disk), and the other is AOF (append only file) Persistence (the principle is to write Reids' operation log to the file in an appended manner).
RDB persistence refers to writing a snapshot of the data set in memory to disk within a specified time interval. The actual operation process is to fork a child process and first Write a temporary file. After the writing is successful, replace the previous file and store it with binary compression. (Recommended learning: Redis Video Tutorial)
AOF persistence records every write and delete operation processed by the server in the form of a log. Query operations will not be recorded, but will be recorded in the form of text. , you can open the file to see detailed operation records.
The difference between RDB persistence and AOF persistence:
1. Store data
RDB persistence saves all key-value pairs in the key space ( Including data in expired dictionaries), and are saved in binary form, complying with RDB file specifications, and will be processed differently according to different data types.
AOF persistently saves all write commands executed by the redis server to record the database status. The commands are stored in the aof_buf buffer before writing.
2. Persistence time selection
RDB persistence sets the persistence behavior (number of modifications per unit time) through the save option of conf.
AOF persistence sets the persistence behavior (number of modifications per unit time) through the appendfsync option of conf.
3. Data restoration
RDB persistence: The server loads the RDB file, blocks the thread, and does not accept any commands until the loading is completed.
AOF persistence: The server creates a pseudo client without a network connection, reads all commands in the aof file and executes it (the redis service will select the aof file to restore the database state when the redis service enables aof persistence when the server starts)
4. Expired keys
RDB persistence will ignore expired keys when writing or reading
AOF persistence will not ignore expired keys when the keys are lazily deleted Or append a delete command to the aof file when deleting regularly
5. File size
RDB persistence changes with the amount of stored data (there are different data compression optimizations according to different data types) )
AOF persistence increases with the number of executed commands (optimized through aof rewriting)
For more redis-related technical knowledge, please visit Redis usage tutorialColumnLearn!
The above is the detailed content of What is the difference between the two persistence methods of redis. For more information, please follow other related articles on the PHP Chinese website!