Redis with Nosql: persistence mechanism (snapshot and aof)

Source: Internet
Author: User
In general, data persistence stores data on disks to ensure that data is not lost due to factors such as power outages. Redis often needs to synchronize data in the memory to the disk to ensure persistence. Redis supports two persistence Methods: Snapshotting (snapshot) and Append-onlyfile (aof ).

In general, data persistence stores data on disks to ensure that data is not lost due to factors such as power outages. Redis often needs to synchronize data in the memory to the disk to ensure persistence. Redis supports two persistence Methods: Snapshotting (snapshot) and Append-only file (aof ).

Data PersistenceIn general, data is stored on the disk to ensure that data is not lost due to factors such as power failure.
Redis often needs to synchronize data in the memory to the disk to ensure persistence. Redis supports two persistence methods:Snapshotting (snapshot)It is also the default method, and the other isAppend-only file (aof)Method
Snapshot method:
In this way, the data in the memory is written to the binary file as a snapshot. The default file name isDump. rdb(In the bin directory of redis ).
You can configure and set Automatic snapshot persistence. We can configure redis to automatically create snapshots if more than M keys are modified within n seconds.
Save 900 1 # if more than one KEY is modified within 900 seconds, a snapshot is initiated.
Save 300 10 # if more than 10 keys are modified within 300 seconds, a snapshot is initiated.

Snapshot storage mechanism:
1: redis first calls the fork sub-process,
2: The sub-process is responsible for writing the memory content to the temporary file.
3: when the sub-process writes a snapshot to a temporary file, it replaces the original snapshot file. The sub-process exits.
Snapshots are taken at intervals. If redis is accidentally down, all modifications made during the last snapshot will be lost.
Every snapshot persistence writes the memory data completely to the disk once, not incremental synchronization of dirty data only. If the data volume is large and there are many write operations, a large number of disk I/O operations will inevitably occur, which may seriously affect the performance.

Aof method:
It has better durability than snapshot because when aof is used, redis will append every write command received to the file through the write function, when redis is restarted, it re-executes the write commands saved in the file to recreate the entire database content in the memory.
The file name is appendonly. aof (some operation commands are stored in the bin directory of redis ).

[Root @ localhost redis] # vi/usr/local/redis/etc/redis. conf
Modify the configuration as follows:
# Enable aof
Change appendonly no to appendonly yes

There are three Synchronization Methods in the Redis configuration file:
# The AOF file is written every time a data modification occurs. The efficiency is the slowest, But it ensures full persistence.
Appendfsync always ??
# Synchronize data every second. This policy is AOF's default policy. Performance and durability have made a good compromise.
Appendfsync everysec
# Never synchronize. High efficiency, but data is not persistent. Persistence is not guaranteed.
Appendfsync no ?????????

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.