当前位置:网站首页>16_ Redis_ Redis persistence
16_ Redis_ Redis persistence
2022-07-02 15:20:00 【Listen to the rain】
Redis Persistence
Redis Is a memory database , If you do not save the database state in memory to disk , So once the server process exits , The database state in the server also disappears . therefore Redis Provides persistence !
RDB (Redis DataBase)

Write the data set snapshot in memory to disk within the specified time interval , That's what jargon says Snapshot snapshot , When it recovers, it reads the snapshot file directly into memory .
Redis Will create... Separately ( fork ) A subprocess to persist , Write the data to a temporary file first , When the persistence process is over , Replace the last persistent file with this temporary file . The whole process , The main process is not going to do anything IO Operation of the . This ensures extremely high performance . If large-scale data recovery is needed , And it's not very sensitive to the integrity of data recovery , that RDB The way is better than AOF It's more efficient .RDB The disadvantage is that the data may be lost after the last persistence . Our default is RDB, In general, you don't need to modify this configuration !
Sometimes in the production environment, we Backup this file !
rdb The saved file is dump.rdb All of them are configured in our configuration file !

Trigger mechanism
1、save When the rules are satisfied , Will automatically trigger rdb The rules
2、 perform flushall command , It will trigger our rdb The rules !
3、 sign out redis, There will be rdb file !
The backup automatically generates one dump.rdb
How to restore rdb file
1、 Only need to rdb The documents are in us redis Just start the directory ,redis It will check automatically when it starts dump.rdb Recover the data !
2、 See where you need to be

advantage :
1、 Suitable for large-scale data recovery !
2、 The integrity of the data is not high !
shortcoming :
1、 Need a certain time interval process operation ! If redis Unexpected downtime , There is no need to modify the data for the last time !
2、fork Process time , Will take up a certain amount of content space !!
AOF(Append Only File)
Record all our orders ,history, When restoring, execute the file all over again !

Log every write operation in the form of a log , take Redis All instructions executed are recorded ( Reading operation does not record ), Only files can be added but not rewritten ,redis At the beginning of startup, it will read the file and rebuild the data , In other words ,redis In case of restart, execute the write instruction from the front to the back according to the contents of the log file to complete the data recovery

Not on by default , We need to configure it manually ! We just need to put appendonly Change it to yes It opens. aof !
restart ,redis It's going to take effect !
If this aof There is an error in the file , Now redis The server cannot be started , We need to fix this aof file
redis Provides us with a tool redis-check-aof --fix

If the file is normal , Restart and you can recover directly !
aof To configure :
Redis And AOF Rewriting and its implementation principles
Rewriting rule :aof The default is unlimited appending of files , The file will get bigger and bigger !
If aof File is larger than 64mb, Indicates that the file is too large ! redis will fork A new process to rewrite our files
advantage :
1、 Every change is synchronized , The integrity of the document would be better !
2、 Synchronize once per second , One second of data could be lost
3、 No synchronization , The most efficient !
shortcoming :
1、 Relative to data files ,aof Far greater than rdb, It's faster than rdb slow !
2、Aof It's more efficient than rdb slow , So we redis The default configuration is rdb Persistence !
Expand
1、RDB Persistence mode can snapshot your data in a specified time interval
2、AOF Persist to record every write to the server , These commands are reexecuted when the server restarts to restore the original data ,AOF Command to Redis Protocol append saves each write to the end of the file ,Redis Also able to AOF The file is rewritten in the background , bring AOF The size of the file should not be too large .
3、 Cache only , If you only want your data to exist when the server is running , You can also use no persistence
4、 Open two persistence methods at the same time
- under these circumstances , When redis It will be loaded prior to restart AOF File to restore the original data , Because in general AOF The data set saved by the file is better than RDB The data set of the file should be complete .
- RDB The data is not real-time , When using both, the server will only look for AOF file , Do you want to use only AOF Well ? The author suggests not to , because RDB Better for backing up databases (AOF It's not easy to backup in constant change ), A quick restart , And there won't be AOF May be latent Bug, Keep it as a means in case .
5、 Performance Suggestions
- because RDB The documents are for backup purposes only , The advice is only in Slave On persistence RDB file , And as long as 15 One minute backup is enough , Only keep save 900 1 This rule .
- If Enable AOF, The advantage is that in the worst case, it will only lose no more than two seconds of data , The startup script is simple load Their own AOF Just file it , The first is to bring about continuous IO, Two is AOF rewrite At the end of rewrite The blocking caused by writing new data to new files is almost inevitable . As long as the hard disk is licensed , We should try to minimize AOF rewrite The frequency of ,AOF Overridden base size default 64M Is too small , It can be set to 5G above , Default over original size 100% The size rewrite can be changed to the appropriate value .
- If you don't Enable AOF, Only by Master-Slave Replcation High availability can also be achieved , Can save a lot of IO, And less rewrite The fluctuation of the system caused by . The price is if Master/Slave At the same time ( power failure ), It will lose more than ten minutes of data , There are also two startup scripts to compare Master/Slave Medium RDB file , Load the newer one , Microblogging is this kind of Architecture .
边栏推荐
- 2021-2022学年编译原理考试重点[华侨大学]
- 04_ Stack
- LeetCode 209. Minimum length subarray
- Record an error report, solve the experience, rely on repetition
- [noi Simulation Competition] scraping (dynamic planning)
- How to solve the problem of database content output
- 学习使用php实现公历农历转换的方法代码
- 二叉树的遍历方式主要有:先序遍历、中序遍历、后序遍历、层次遍历。先序、中序、后序其实指的是父节点被访问的次序。若在遍历过程中,父节点先于它的子节点被访问,就是先序遍历;
- [noi simulation] Elis (greedy, simulation)
- 11_Redis_Hyperloglog_命令
猜你喜欢

MFC timer usage

MFC 定时器使用

做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统

实用调试技巧

工程师评测 | RK3568开发板上手测试

TiDB数据迁移工具概览
![[C language] explain the initial and advanced levels of the pointer and points for attention (1)](/img/61/1619bd2e959bae1b769963f66bab4e.png)
[C language] explain the initial and advanced levels of the pointer and points for attention (1)

15_Redis_Redis.conf详解

IE 浏览器正式退休

Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
随机推荐
2021-2022學年編譯原理考試重點[華僑大學]
TiDB跨数据中心部署拓扑
C语言中的算术运算及相关练习题
让您的HMI更具优势,FET-G2LD-C核心板是个好选择
C语言习题---(数组)
List集合&UML图
Solve the problem that El radio group cannot be edited after echo
TiDB 集群最小部署的拓扑架构
C# richTextBox控制显示最大行数
Kibana basic operation
C language exercises - (array)
[C language] explain the initial and advanced levels of the pointer and points for attention (1)
MFC 控制台打印,弹出对话框
The past and present lives of visual page building tools
Practical debugging skills
Solution of Queen n problem
07_哈希
Printf function and scanf function in C language
05_队列
CDN 在游戏领域的应用

