当前位置:网站首页>Redis - persistent RDB and persistent AOF
Redis - persistent RDB and persistent AOF
2022-06-30 18:25:00 【Salted fish_ Turn over】
List of articles
brief introduction
because Redis It's a memory based database , If you do not save the database state in memory to disk , So once the data server process exits , The database state in the server will disappear , therefore Redis Provides persistence , Persisting data from memory to a file .
There are two ways to persist :
RDB
AOF
These two persistence methods will be introduced below
RDM
1. What is? RDM
RDB, Full name Redis DataBase, Writes a dataset snapshot to disk within a specified time interval , Read these snapshot files into memory when recovering data , In the corresponding configuration file SNAPSHOTTING.
Redis A child process will be created separately fork,fork Is to copy a process exactly like the current process as a child process of the original process for persistence ,fork The data is written to a temporary file , After the persistence operation is completed , The temporary file will replace the file that has been persisted , In the process , The main process does not perform any IO operation , This ensures that RDB Extremely high performance , Compared with RDB and AOF,RDB The mode of AOF More efficient . If you are recovering big data , And the accuracy of the data is not high , Then you can use it RDB,Redis The persistence of the default is also RDB, In general ( Production environment ) There is no need to modify this configuration .
By default , Redis Save the database snapshot in a file named dump.rdb In the binary file of . The file name can be customized in the configuration file , Sometimes in the production environment, we Backup this file !
2.RDB The trigger mechanism of
1、 Meet the requirements of the configuration file save In the case of rules , Will automatically trigger RDB The rules
2、 perform FLUSHALL command , It will also trigger RDB The rules , But it doesn't make sense , Because the file content is empty
3、 sign out Redis, There will be dump.rdb file ( sign out Redis Default execution save command )
4、 Use... In the client save perhaps bgsave command , It can also trigger RDB But the two rules are different
save The command will completely occupy the current process for persistence operation , in other words ,save Order just save , No matter what else , As long as there is progress coming , All blocked
bgsave The command runs in the background , Manual fork Child processes operate , And it will respond to the request of the client
3.RDB Data recovery

1、 First, use a Redis Command to view the location where the persistent file is saved
2、 And then dump.rdb Files in Redis Under the startup directory of
4.RDB Advantages and disadvantages
advantage :
1、 Suitable for large-scale data repair .
2、 The requirement for data accuracy is not high .
shortcoming :
1、 A certain time interval is required for persistence , If the server goes down unexpectedly within a certain interval , Then the last persistent data will be lost .
2、 because RDB Persistence is required fork Part of the process IO Operation of the , in other words , Copy an identical process from the original process and run it in memory as a child process , The memory load will double .
AOF
1. What is? AOF
Redis Another way to persist ,AOF, Full name Append Only File, It records every write operation in the form of log , take Redis Record the executed commands ( Reading operation does not record ), Just append files , Do not overwrite the file .Redis It will load automatically at startup AOF Persistent files rebuild data , That is to say Redis Restart will AOF The information in the persistent file is executed from front to back to complete the data recovery .
AOF The location of the configuration file corresponding to persistence is APPEND ONLY MODE
2. start-up AOF

After modifying the configuration , Just restart . if appendonly.aof Some errors occurred in the contents of the file , So in Redis When starting , There will be problems .
Redis Of AOF The name of the persistent file is called appendonly.aof
Here's a little detail to note : If AOF and RDB If the mode is enabled in the configuration file , In order to ensure the security of data , stay Redis It will be used preferentially at startup AOF.
3. Repair AOF file
If appendonly.aof There was an internal error ,Redis Provides a fixable aof The file repair tool is called redis-check-aof

4.AOF Rewriting rule
Rewriting is the merging of commands that can be merged , For example, operate one more time key, Can be merged into one , invalid key All operations can be deleted .
Redis The last rewritten AOF File size is recorded , If the size of the current file is more than twice the size of the source file and the size is greater than 64M Will trigger the rewrite operation .
5.AOF Advantages and disadvantages
advantage :
It supports Synchronous recording and Asynchronous recording , The properties of the corresponding configuration file are as follows :
appendfsync always # Synchronous recording , There is a write operation in the client , Record immediately , Good data integrity , But the performance is poor
appendfsync everysec # Asynchronous recording , Once per second , But if the server goes down within this second , This second of data will be lost
appendfsync no # Don't record , It's also the most efficient
shortcoming :
1、 From a data recovery perspective ,AOF The amount of data recovered must be greater than RDB Big , The repair speed will be slow .
2、 In terms of time to recover data ,AOF Time is also greater than RDB Of .
RDB and AOF The choice of

Be careful :
1、RDB You can persist a snapshot of a dataset within a specified time interval .
2、AOF Persistent records are sent to each client Redis Server write operations , When the server restarts, the command will be executed again to recover the original data ,AOF Each persistent record is appended to the end of the file , also Redis The existence of rewriting mechanism makes AOF The file is controlled at a reasonable size
3、 If Redis Cache only , If you only want the data to exist when the server starts up , You don't have to use any persistence
4、 If both persistence are enabled at the same time ,Redis The server will find first by default AOF Persistence , because AOF It's better to save data sets than RDB To be complete , This is the same. Redis Consider safety reasons .
边栏推荐
- Customer relationship CRM management system based on SSH
- 剑指 Offer 16. 数值的整数次方
- Do you write API documents or code first?
- Vscode status bar statusbar
- New research of HKUST & MsrA: about image to image conversion, finishing is all you need
- MySQL reports that the column timestamp field cannot be null
- 【云驻共创】Huawei iConnect使能物联终端一触即联
- Sign up for Huawei cloud proposition in the "Internet +" competition, and you can take many gifts!
- Three methods of modifying time zone in MySQL
- Redis (VII) - sentry
猜你喜欢

Conception d'un centre commercial en ligne basé sur SSH

Post office - post office issues (dynamic planning)

Shortcut keys for the rainbow brackets plug-in

Another CVPR 2022 paper was accused of plagiarism, and Ping An insurance researchers sued IBM Zurich team

Apache 解析漏洞(CVE-2017-15715)_漏洞复现

Design of online shopping mall based on SSH

漏洞复现----35、uWSGI PHP 目录遍历漏洞 (CVE-2018-7490)

Redis (IV) - delete policy

The new Post-00 Software Test Engineer in 2022 is a champion

Do you write API documents or code first?
随机推荐
Partition marble (multiple knapsack + binary optimization)
Shortcut keys for the rainbow brackets plug-in
Volcano engine was selected into the first "panorama of edge computing industry" in China
It's not easy to say I love you | use the minimum web API to upload files
Deep understanding of JVM (IV) - garbage collection (I)
ABAP-发布Restful服务
Redis (II) -- persistence
Vscode status bar statusbar
AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
Rainbow Brackets 插件的快捷键
Post office - post office issues (dynamic planning)
Design of online shopping mall based on SSH
剑指 Offer 17. 打印从1到最大的n位数
What should I pay attention to when playing futures? Where is safe to open an account? It's my first contact
力扣解法汇总1175-质数排列
100 examples of bug records of unity development (the first example) -- shader failure or bug after packaging
.NET ORM框架HiSql实战-第一章-集成HiSql
MySQL找不到mysql.sock文件的临时解
Tencent cloud installs MySQL database
又一篇CVPR 2022论文被指抄袭,平安保险研究者控诉IBM苏黎世团队