test environment:
windows
RDB trigger mechanism
save bgsave flushall is automatically triggered (configuration file configuration)
The save command triggers:
Trigger method: first manually delete the dump.rdb file.
When the save command is executed, the dump.rdb file is automatically generated and the test is successful
The bgsave command triggers:
Trigger method: manually delete the dump.rdb file
When the bgsave command is executed, the dump.rdb file is automatically generated and the test is successful
Operation analysis: When this command is executed, Redis will perform snapshot operations asynchronously in the background, and snapshots can also respond to client requests. The specific process is that the Redis process executes the fork operation to create a child process, and the RDB persistence process is the responsibility of the child process, which ends automatically after completion. Blocking only occurs during the fork phase, generally for a short time. The bgsave command is also the default mode for Redis internal RDB operations .
The flushall command triggers
Trigger method : manually delete the dump.rdb file, and then trigger the flushall command.
When the flushall command is executed, the dump.rdb file is automatically generated and the test is successful
save and bgsave
Way | save command | bgsave command |
---|---|---|
read and write | Synchronize | asynchronous |
blocking client commands | yes | no |
additional memory consumption | no | yes |
start new process | no | yes |
restore rdb file
First delete dump, rdb files
delete key
Restore the data in dump.rdb
Just start redis-server.exe directly in the windows environment (put it in the bin directory in the linux environment), and the test is successful
Advantages and disadvantages of RDB persistence
shortcoming:
The last modified data will be lost when the server is down
When persisting, a child process will be fork, which will occupy a certain amount of memory space
advantage:
Suitable for large-scale data recovery!
The integrity of the data is not required!
RDB persistence summary:
RDB is the default persistence method of redis.
The RDB persistence trigger methods include save (not commonly used), bgsave, flushall, and save [time] [operationChange] configured in the configuration file (the test has not taken effect).
RDB persistence process
It refers to writing the snapshot of the data set in the redis memory to the disk within the specified time interval. The realization principle is that the redis service first forks a child process within the specified time interval, and the child process writes the data set into a temporary file. After the write is successful , and then replace the previous file, store it with binary compression, generate a dump.rdb file and store it on the disk.