Redis persistence mechanism

Source: Internet
Author: User

Redis is an in-memory database that supports persistence, which means that Redis often needs to synchronize the in-memory data to the hard disk to ensure persistence.

Redis supports two persistence modes:

1. Snapshot (snapshot), is also the default mode;

This is done by writing the in-memory data to the binary file as a snapshot, with the default file name Dump.rdb. You can automate snapshot persistence by configuring settings.

Save 1 #900秒内如果超过1个key被修改, the snapshot is initiated
Save #300秒内如果超过10个key被修改, the snapshot is initiated
Save 10000 #60秒内如果超过10000个key被修改, the snapshot is initiated

As we can see, there is no Dump.rdb file when the Redis is finished, the system automatically generates DUMP.RDB when the snapshot requirements are met, and the file type is a binary file.

2.append-only file (aof) mode;

Because the snapshot is done at a certain interval, if Redis accidentally falls down, all modifications after the last snapshot are lost.

AOF is more persistent than snapshot mode, because Redis appends each command received to the file via the Write function when using AOF, and when Redis restarts, it is re-executed by the

Write commands to rebuild the entire contents of the database in memory.

Of course, because the OS caches write modifications in the kernel, it may not be written to disk immediately. This way, the persistence of the AoF method is also likely to lose some modifications

The configuration file tells Redis the time we want to force the OS to write to disk through the Fsync function.

Appendfsync always #收到命令立即写入磁盘, the slowest, but guaranteed full persistence

Appendfsync everysec #每秒钟写入磁盘一次, a good compromise in performance and persistence

Appendfsync no #完全依赖os, best performance, no guarantee of durability

Let's take a look at the shell:

Edit redis.conf file, modify AppendOnly No to appendonly Yes

Start Redis again and add a key

We can see that the system automatically generated a appendonly.aof file, and non-binary, we use cat to view, in fact, the store is the new command we just added.

Redis persistence mechanism

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.