Introduction to redis persistence rdb aof

 

 

The persistence of rdb is done through snapshots. When certain conditions are met, redsi will automatically snapshot all the data in memory and store it on the hard disk. By default, it is stored in the dump.rdb file in the redis root directory.
RDB is the default persistence method used by redis. The configuration information is
periodically generated in the configuration file redis.conf to generate snapshots of memory data (that is, the backup of data at a certain point in time) and then stored on the hard disk.

Snapshot execution timing:
save 900 1: Indicates that at least one key is changed within 900 seconds and a snapshot is taken.
save 300 10
save 60 10000

Manually execute the save or bgsave command to let redis perform snapshots.
The difference between the two commands is that save is a snapshot operation performed by the main process, which blocks other requests. bgsave will perform snapshot operations by fork child processes.
The process of redis implementing snapshots:
1: Redis uses the fork function to copy a copy of the current process (child process)
2: The parent process continues to receive and process commands from the client, while the child process begins to write the data in memory to the hard disk Temporary file
3 in : When the child process writes all the data, it will replace the old RDB file with the temporary file. At this point, a snapshot operation is completed.

Note: Redis will not modify the RDB file during the snapshot process, and will replace the old file with the new one only after the snapshot ends, which means that the RDB file is complete at any time.
This allows us to back up the redis database by regularly backing up the RDB file. The
RDB file is a compressed binary file, and the space occupied will be smaller than the data in the memory, which is more convenient for transmission.

 

File repair: redis-check-dump is used to repair dump files when redis fails to start

Advantages and disadvantages of rdb
Advantages: Since there are data snapshot files stored, it is very convenient to restore data.
Disadvantage: All data changed since the last snapshot will be lost.


The data scheme saved by AOF is the most complete. If rdb and aof are enabled at the same time, the aof method will be used. The aof method will
 
be persisted through log files. By default, redis does not enable aof, which can be enabled by the parameter appendonly parameter.
appendonly yes
The save location of the aof file is the same as the location of the rdb file, which is set by the dir parameter. The default file name is appendonly.aof, which can be modified by appendfilename parameter
appendfilename appendonly.aof
aof log file rewrite
auto-aof-rewrite- percentage 100
auto-aof-rewrite-min-size 64mb
manually execute bgrewriteaof to rewrite
redis write command synchronization timing
appendfsync always execute
appendfsync everysec everysec execute a synchronization operation every second by default (recommended)
appendfsync no does not actively synchronize, by The operating system does it, and repairs files every 30 seconds
: redis-check-aof
dynamically switches the redis persistence mode, from RDB to AOF (supports Redis 2.2 and above)
CONFIG SET appendonly yes
CONFIG SET save "" (optional)

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327049520&siteId=291194637