Redis is called an in-memory database because it stores all its data in memory, so Redis has strong speed performance. However, precisely because the data is stored in memory, when Redis is restarted, all Data stored in memory will be lost. In order to make data persistent, Redis provides two methods: RDB method and AOF method.
1. RDB method
RDB method persistence is completed through snapshotting. Under certain conditions, Redis will automatically generate a copy of all the data in the memory and store it on the hard disk. This process is called a "snapshot". "Snapshot" is similar to taking a photo. The moment you press the shutter, the photo you freeze is called a "snapshot".
# Redis There are 4 cases of snapshots on the data: (Recommended Learning: Redis Video Tutorial )
## automatically;2. AOF method
Persistence is achieved through RDB. Once Redis exits abnormally, all data changed after the last snapshot will be lost. In order to reduce the risk of data loss caused by process termination, the AOF method can be used to achieve data persistence.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. Details can be seen in the file. operation records.
Her appearance is to make up for the shortcomings of RDB (data inconsistency), so it uses the form of a log to record each write operation and append it to the file. When Redis is restarted, the write instructions will be executed from front to back based on the contents of the log file to complete the data recovery work. By default, Redis does not enable AOF persistence. It can be started through the appendonly parameter: appendonly yesThe above is the detailed content of How does redis persist data?. For more information, please follow other related articles on the PHP Chinese website!