Home  >  Article  >  Database  >  How to implement redis data persistence

How to implement redis data persistence

尚
Original
2019-07-05 15:53:2710769browse

How to implement redis data persistence

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

How to implement redis data persistence

3. Default backup file name

How to implement redis data persistence

4. The default backup RDB file location

How to implement redis data persistence

How to implement redis data persistence

5. You can also actively trigger the saving of redis data snapshot, the operation is as follows

How to implement redis data persistence

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

How to implement redis data persistence

Set the AOF synchronization method. The default setting here is to synchronize once per second.

How to implement redis data persistence

3. After turning on the AOF synchronization mode, back up the file It’s like this

How to implement redis data persistence

#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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn