当前位置:网站首页>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 .
边栏推荐
- [sword finger offer] 52 The first common node of two linked lists
- [machine learning] K-means clustering analysis
- 基于SSH的通讯网络电子计费系统
- Switching routing (VLAN) experiment
- 抖音最新Xbogus,signature生成js逆向分析
- Synchronized summary
- 基于SSH的网上商城设计
- Grep output with multiple colors- Grep output with multiple Colors?
- Thinking on large file processing (upload, download)
- Three methods of modifying time zone in MySQL
猜你喜欢

基于SSH的通讯网络电子计费系统

Communication network electronic billing system based on SSH

Small tools (3) integration knife4j3.0.3 interface document

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

Deep understanding of JVM (III) - memory structure (III)

剑指 Offer 16. 数值的整数次方

Simulation of campus network design based on ENSP

Post penetration file system + uploading and downloading files

Redis (IX) - enterprise level solution (II)

Hcip (Huawei Senior Network Security Engineer) (Experiment 8) (MPLS basic experiment)
随机推荐
Research on the principle of Tencent persistence framework mmkv
Type ~ storage ~ variable in C #
Distributed machine learning: model average Ma and elastic average easgd (pyspark)
分布式场景下,你知道有几种生成唯一ID的方式嘛?
Php8.0 environment detailed installation tutorial
Openlayers 卷帘地图
Redis (II) -- persistence
Alexnet of CNN classic network (Theory)
漏洞复现----37、Apache Unomi 远程代码执行漏洞 (CVE-2020-13942)
Babbitt | yuanuniverse daily must read: minors ask for a refund after a reward. The virtual anchor says he is a big wrongdoer. How do you think of this regulatory loophole
TeamTalk WinClient编译问题及解决方案
MySQL找不到mysql.sock文件的临时解
Design of online shopping mall based on SSH
Elastic 8.0: opening a new era of speed, scale, relevance and simplicity
LRN local response normalization
Post MSF infiltration summary
Talk about the SQL server version of DTM sub transaction barrier function
Redis (I) - data type
uni-app进阶之内嵌应用【day14】
Small Tools(3) 集成Knife4j3.0.3接口文档