RDB data persistence (theory)
Persistence principle:
RDB is snapshot snapshot storage and is the default persistence method.
RDB will periodically save the data to disk according to a certain strategy. (the next cycle will be a failure on arrival, and data will be lost)
With the help of the copy on write mechanism of the fork command, the current process is fork out of a child process when the snapshot is generated.
Then cycle through all the data in the child process and write the data into a RDB file.
Advantages: using a single child process for persistence, the main process will not do any IO operation, ensuring the high performance of redis.
Disadvantages: RDB is persisted according to periodic strategy
If redis fails during persistence, data loss will occur.
So this method is suitable for the environment where the data requirements are not strict.
Profile related parameters:
Dbfilename dump.rdb # specify persistent data file name
Dir / usr/local/redis-3.0.6-6379 / # default dir. /
Save 900 1
Save 300 10
Save 60 10000
Persistence process:
When the conditions of save are met, such as changing 1 key,900s, the data will be written to a temporary file.
Replace the temporary file with the old dump.rdb when the persistence is complete.
Use RDB to recover data: (it takes time)
Restart the server of redis (data will be synchronized from dump.rdb when starting server of redis)
Use the command to persist save storage:
. / redis-cli-h ip-p port save # Front desk for storage
. / redis-cli-h ip-p port bgsave # storage in the background