Redis Learning (iv) Redis persistent RDB, AOF

Source: Internet
Author: User
Tags redis server

Redis is an in-memory database that stores data in memory, which creates new problems with data security while speeding up the read speed, meaning that all data in the Redis database will be lost when the Redis server has crashed. To solve this problem, Redis provides persistent functionality--rdb and aof. In layman's words, the data in memory is written to the hard disk.

I.. RDB Persistence

RDB persistence refers to writing a snapshot of an in-memory dataset to disk at a specified time interval, where the actual operation is to fork a child process, write the dataset to a temporary file, and then replace the previous file with a successful write. When the server on which Redis resides is down, restarting automatically loads the Rdb file and recovers the data. In real production, an RDB backup file is typically saved on two servers. Prevent server failures and backup files are lost.

1. Automatic triggering

In the Conf configuration file:

 the 1   10000  

Note: You can disable the Save function by commenting out all the save lines. You can also deactivate by simply using an empty string: Save ""
An RDB is triggered when one of the above three conditions is met

2. Manual Trigger

Of course, if the above conditions are not met, the RDB can also be triggered manually

1), save is a blocking RDB persistence, when this command is executed, the master process of Redis writes the database state in memory to the Rdb file, until the time the file is created, Redis will not be able to process any command requests.

2), Bgsave is non-blocking persistence, it will create a sub-process specifically to the in-memory database state to the Rdb file, while the main process can also handle command requests from the client. However, the child process is basically the parent process of replication, which is equal to two redis processes of the same size running on the system, resulting in a significant increase in memory utilization.

127.0. 0.1:6379>127.0. 0.1:6379>127.0. 0.1:6379>
3. Advantages and Disadvantages

Advantages:

1, in this way, once the system fails, you can use the Rdb file for recovery

2, in the beginning of the persistence, the only thing it needs to do is fork out the sub-process, then the child process to complete these persistent work, which can greatly avoid the service process to perform IO operations.

3, the RDB uses the full amount of write, when the data changes, will generate a new RDB file to replace the old Rdb file, relative to the Aof,rdb recovery start more efficient

Disadvantages:

1. Once the system is down before the scheduled persistence, the last data that is not written to the disk will be lost.

2. Since the RDB assists with data persistence through the fork process, it can cause the entire server to stop serving hundreds of milliseconds, or even 1 seconds, if the data set is large.

First, aof persistence

Unlike the RDB's preservation of the entire Redis database state, AOF records the state of the database by saving write commands (such as set, Sadd, Rpush) on the Redis server, saving you from writing to the Redis database, appending files, not overwriting files, The Redis startup early reads the file and executes the write instruction from the front to the back to complete the recovery work of the data.

1. Configuration
" appendonly.aof "
AppendOnly no modified to appendonly Yes
Appendfsync Alwaysappendfsync Everysecappendfsync No

No means that the fsync is not executed and the operating system guarantees that data is synchronized to disk at the fastest speed.
Always means that each write executes fsync to ensure that data is synchronized to disk.
Everysec indicates that Fsync is executed once per second and may result in the loss of this 1s data

If Redis turns on the AOF persistence feature, the AoF file will be used to restore the database first when the Redis service restarts.

2. aof File Repair

In the unlikely event that the aof file is compromised, you can use the command Redis-check-aof.exe appendonly.aof to fix it.

3. Advantages and Disadvantages

Advantages:

1), Redis provides 3 of the synchronization policy, that is, synchronization per second, each modified synchronization and unsynchronized. The default policy is synchronization per second, high efficiency, once the system is down, then only the data modified within one second will be lost.

2), the use of incremental write, in the process of writing even if there is an outage, it will not destroy the log files already exist in the content. Even if garbled, you can use the Redis-check-aof tool to help us solve the problem of data consistency.

3), if the log is too large, Redis can automatically enable the rewrite mechanism.

4). AOF contains a well-formed, easy-to-understand log file for recording all modification operations. The user can complete the reconstruction of the data through this file.

Disadvantages:

1). aof files are typically larger than the Rdb file for the same number of datasets. An RDB recovers a large data set faster than AOF.

2). Depending on the synchronization strategy, the AOF is often slower than the RDB in terms of operational efficiency. In summary, the efficiency of the synchronization policy per second is high, and the efficiency of the synchronization disable policy is as efficient as the RDB.


Redis Learning (iv) Redis persistent RDB, AOF

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.