Redis Persistence Scheme Rdb and aof (theory)

Source: Internet
Author: User
Tags redis

What is the difference between Redis and memcache?

Simply put, if you don't have a persistent redis, it's just like Memcache, which is the equivalent of a cache database.


How does Redis solve data persistence?

Redis has two persistence scenarios: RDB (Redis DataBases) and aof (AppendOnly File)


RDB Persistence (Detailed analysis: http://blog.51cto.com/13690439/2118462)

An RDB is a snapshot snapshot < binary file > store, which is the default persistence mode.

The RDB will periodically save the data to disk according to a certain policy. (The next cycle is a fault on arrival, data will be lost)

With the copy on write mechanism of the fork command, when the snapshot is generated, the current process is forked out to a child process,

It then loops all the data in the subprocess and writes the data to the Rdb file.


AOF Persistence (Detailed analysis: http://blog.51cto.com/13690439/2118465)

aof< binary file > has better durability than the Rdb method.

Redis appends each received write command to the last file, similar to the MSYQL Binlog, through the Write function.

When Redis restarts, the contents of the entire database are rebuilt in memory by re-executing the write commands saved in the file.


In simple terms:

RDB: The persistent data is carried out periodically according to the policy;

AOF: is constantly to record the modification operation;


Choice of persistence mode:

Both the RDB and AOF operations are sequential IO operations with high performance.

At the same time, when the database is restored through the Rdb file or the AOF log, the sequential read data is loaded into memory.

So it does not cause random reads of the disk.


In general, if you want to provide high data supportability, it is recommended that you use both persistence methods at the same time.

If you can accept a few minutes of data loss from a disaster, you can use only an RDB.


In terms of data recovery:

The RDB has a shorter startup time for two reasons:

1. The Rdb file has only one record per piece of data, and does not have a record of multiple operations of the data, as in the case of aof logs.

So every piece of data just needs to be written once.

2, the RDB file storage format and the Redis data in memory encoding format is consistent, do not need to do data coding work,

Therefore, the CPU consumption is much smaller than the AOF log load.

Market Common structure:

At present, the usual design idea is to use the replication mechanism to compensate for aof, snapshot performance deficiencies, to achieve data persistence.

That is, master on snapshot and aof do not do, to ensure that master read and write performance,

On the slave, snapshot and aof are also turned on to ensure the security of the data.


Redis Persistence Scheme Rdb and aof (theory)

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.