当前位置:网站首页>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 .
边栏推荐
- hdfs上的数据导入到clickhouse用什么方式最快呢?spark通过jdbc导入,还是hdfs
- Deep understanding of JVM (V) - garbage collection (II)
- 【机器学习】K-means聚类分析
- What will be the game changes brought about by the meta universe?
- Advanced embedded application of uni app [day14]
- Do fresh students get a job or choose a job after graduation?
- Tencent cloud installs MySQL database
- Animesr: learnable degradation operator and new real world animation VSR dataset
- Vulnerability recurrence ----- 38. Thinkphp5 5.0.23 Remote Code Execution Vulnerability
- 又一篇CVPR 2022论文被指抄袭,平安保险研究者控诉IBM苏黎世团队
猜你喜欢

Customer relationship CRM management system based on SSH

Simulation of campus network design based on ENSP

基于SSH的网上商城设计

Talk about the SQL server version of DTM sub transaction barrier function

What did Tongji and Ali study in the CVPR 2022 best student thesis award? This is an interpretation of yizuo

MySQL advanced - basic index and seven joins
![The company was jailed for nonstandard bug during the test ~ [cartoon version]](/img/cd/42ab3fc0000fa7dfe2ac89de3486e4.jpg)
The company was jailed for nonstandard bug during the test ~ [cartoon version]

Daily interview 1 question - how to prevent CDN protection from being bypassed

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

Animesr: learnable degradation operator and new real world animation VSR dataset
随机推荐
MSF后渗透总结
腾讯云安装mysql数据库
Sign up for Huawei cloud proposition in the "Internet +" competition, and you can take many gifts!
Do you write API documents or code first?
Tsinghua only ranks third? 2022 release of AI major ranking of Chinese Universities of soft science
uni-app进阶之内嵌应用【day14】
C语言结构体
基于eNSP的校园网设计的仿真模拟
力扣解法汇总1175-质数排列
联想“双平台”运维解决方案 助力智慧医疗行业智慧管理能力全面提升
Lenovo's "dual platform" operation and maintenance solution helps to comprehensively improve the intelligent management ability of the intelligent medical industry
Another CVPR 2022 paper was accused of plagiarism, and Ping An insurance researchers sued IBM Zurich team
Post office - post office issues (dynamic planning)
Customer relationship CRM management system based on SSH
MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等
后渗透之文件系统+上传下载文件
Do fresh students get a job or choose a job after graduation?
C# Winform程序界面优化实例
Only black-and-white box test is required for test opening post? No, but also learn performance test
The company was jailed for nonstandard bug during the test ~ [cartoon version]