Two ways to implement data persistence with Redis:
RDB: Save data snapshots within a specified time interval
AOF: First put the command Append to the end of the operation log and save all historical operations
1. RDB implements Redis data persistence (default mode)
1. Edit redis.conf
Note: Use the whereis redis command to check where redis is installed, then enter the etc directory of the redis installation directory and edit redis.conf.
2. Default backup time interval
3. Default backup file name
4. The default backup RDB file location
5. You can also actively trigger the saving of redis data snapshot, the operation is as follows
6. Disadvantages
Because persistence is performed under specific conditions (every once in a while), it may cause redis to crash and when it is restored again, Some data may be lost.
2. AOF persistence solution
First append the command to the end of the operation log and save all historical operations.
1. Advantages compared to RDB persistence solution:
(1) The data is very complete, and less data is lost in failure recovery
(2) Historical operations can be processed Processing
2. How to enable AOF persistence mode
After changing the appendonly parameter in the redis.conf configuration file to yes, redis will start the AOF data persistence mode
Set the AOF synchronization method. The default setting here is to synchronize once per second.
3. After turning on the AOF synchronization mode, back up the file It’s like this
#As you can see from the above, it records all the operation commands since I turned on AOF.
4. Disadvantages
(1) Because AOF mode needs to record every redis command, the file size will be very large
(2) And It will cause the speed to be lower than RDB and the recovery speed is slow
For more Redis related knowledge, please visit the Redis usage tutorial column!
The above is the detailed content of How to implement redis data persistence. For more information, please follow other related articles on the PHP Chinese website!