Home >Database >Redis >Is redis persistence enabled by default?

Is redis persistence enabled by default?

anonymity
anonymityOriginal
2019-06-04 16:16:0613578browse

As we all know, redis is an in-memory database. It stores data in memory, which speeds up reading and also creates new problems for data security. That is, when the server where redis is located goes down, the redis database All data will be lost.

In order to solve this problem, redis provides persistence function. In layman's terms, it means writing the data in the memory to the hard disk.

Is redis persistence enabled by default?

Redis provides a variety of persistence methods at different levels:

1. RDB persistence can be performed at specified time intervals Generate a point-in-time snapshot of the data set.

2. AOF persistently records all write operation commands executed by the server, and restores the data set by re-executing these commands when the server starts. All commands in the AOF file are saved in the Redis protocol format, and new commands will be appended to the end of the file. Redis can also rewrite the AOF file in the background so that the size of the AOF file does not exceed the actual size required to save the data set state.

3. Redis can also use AOF persistence and RDB persistence at the same time. In this case, when Redis restarts, it will give priority to using the AOF file to restore the data set, because the data set saved by the AOF file is usually more complete than the data set saved by the RDB file.

4. Turn off the persistence function. Let the data only exist in the memory, and it will be gone after restarting.

Redis’ RDB persistence (RDB is enabled by default)

1.Snapshotting:

By default, Redis will Dump the snapshot into the dump.rdb file. In addition, we can also modify the frequency of Redis server dump snapshots through the configuration file. After opening the redis.conf file, we search for save and can see the following configuration information:

save 900 1 #at 900 seconds (15 minutes) later, if at least 1 key changes, dump the memory snapshot.

save 300 10 #After 300 seconds (5 minutes), if at least 10 keys have changed, dump the memory snapshot.

save 60 10000 #After 60 seconds (1 minute), if at least 10000 keys have changed, dump the memory snapshot.

2. Dump snapshot mechanism:

1). Redis forks the child process first.

2). The child process writes the snapshot data into the temporary RDB file.

3). When the child process completes the data writing operation, replace the old file with a temporary file.

The above is the detailed content of Is redis persistence enabled by default?. 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