Two ways of Redis persistence and configuration

Source: Internet
Author: User
Tags redis

Redis's excellent performance is because it stores all the data in memory, the same memcached do, but why Redis can stand out, largely because Redis has excellent persistence mechanism to ensure that the server restart, the data will not be lost. Here's a look at how Redis is persisted.


Redis supports the persistence of two ways, one is the RDB way, the other is the AOF way. Either of these can be used individually or in a mixed way.

Introduction of Rdb Method

The Rdb method is done through snapshots, and when a certain condition is met Redis automatically snaps all the data in memory and stores it on the hard disk. Just like taking a picture, save everything in this moment. The conditions for the snapshot are specified in the configuration file. There are two main parameters: time and the number of key values changed, that is, when the number of key changes in the specified time is greater than the execution value, a snapshot is taken. RDB is the default persistence method for Redis.

RDB Mode configuration

Locate the Redis profile: redis.conf

1 Set the trigger condition:



2) Set Rdb file path

The default Rdb file store path is the current directory, and the filename is: Dump.rdb. You can modify the path and file name in the configuration file, respectively, dir and Dbfilename

Redis reads the RDB snapshot file, loads the data from the hard disk into memory, and typically takes about 20-30 minutes to load the 1GB snapshot file into memory.


Rdb How to make a snapshot

RDB Snapshot Process:

1) Redis uses the fork function to copy a copy of the current process (the parent process);

2 The parent process continues to accept and process commands from the client, and the child process begins to write the data in memory to a temporary file on the hard disk;

3 When the child process writes all the data, it replaces the old Rdb file with the temporary file.

Manual snapshots:

If automatic snapshots are not triggered, Redis can be manually snapped, save and Bgsave can perform manual snapshots, and the difference between the two commands is that the main process performs a snapshot operation and the other requests are blocked, while the latter is snapshot operations through the fork child process.

Attention:

Because Redis uses fork to replicate a current process, the child process will occupy the same memory resources as the main process, such as the main process 8G memory, then must have 16G memory at the time of backup, or it will enable virtual memory, very poor performance.


Compression of RDB files

RDB files are too large, can be compressed, redis default to open compression, of course, you can configure the Rdbcompression parameters to disable compression.

Advantages and disadvantages of compression and uncompressed:

Compression:

Benefits: Reduce disk storage space
disadvantage: consume CPU resources
1 2 3

No compression:

Advantages: Do not consume CPU resources
disadvantage: Occupy more disk space
1 2 3

How to choose. Then you need to look at the requirements, look at the server resources situation.

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.