当前位置:网站首页>(2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
(2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
2022-08-11 05:33:00 【Xiao Tan floats in Shanghai】
Body
Why persistence is needed
Redis is an in-memory database.Once the service goes down, all data in memory will be lost.The usual solution is to restore these data from the back-end database, but the back-end database has performance bottlenecks. If it is a recovery of a large amount of data,
1. It will bring huge pressure on the database
2. The performance of the database is not as good as that of Redis.Causes the program to respond slowly.So for Redis, it is crucial to achieve data persistence and avoid restoring data from the back-end database.
Persistence is divided into: AOF and RDB snapshots
RDB snapshot: RDB is the abbreviation of Redis DataBase, the Chinese name is snapshot/memory snapshot. RDB persistence is the process of generating a snapshot of the current process data and saving it to disk. Since it is a snapshot at a certain time, then the snapshot in the snapshotThe value must be earlier than or equal to the value in memory.
AOF storage: Redis is a "post-write" log. Redis executes commands first, writes data into memory, and then records logs.The log records every command received by Redis, and these commands are saved in text form.
The AOF log adopts the log after write, that is, write the memory first, then write the log.
Why log after write?
Redis requires high performance, and using log writing has two advantages:
Avoid additional checking overhead: When Redis logs to AOF, it does not first check the syntax of these commands.Therefore, if you record the log first and then execute the command, the wrong command may be recorded in the log, and Redis may make an error when using the log to restore data.
Does not block the current write operationBut this approach has potential risks:
- If the execution of the command is completed and the machine crashes before writing the log, data will be lost.
- The main thread has a lot of pressure to write to the disk, resulting in slow disk writing and blocking subsequent operations.
How to implement AOF
AOF log records each write command of Redis. The steps are divided into: command append (append), file write (write) and file synchronization (sync).
Command Append When the AOF persistence function is turned on, after the server executes a write command, it will append the executed write command to the server's aof_buf buffer in the protocol format.
File writing and synchronization Redis provides three writeback strategies for when to write the contents of the aof_buf buffer to the AOF file:
Always synchronous writeback: After each write command is executed, the log will be written back to disk synchronously immediately;
Everysec writes back every second: After each write command is executed, just write the log to the memory buffer of the AOF file first, and write the contents of the buffer to the disk every second;
No OS-controlled writeback: After each write command is executed, just write the log to the memory buffer of the AOF file first, and the OS decides when to write the buffer content backdisk.
How to implement AOF storage in Redis!Scroll down
1. Enable AOF persistence
First, you need to enable persistent storage in the redis-master.conf configuration file, and then restart the redis-master master node
1.1 Verify that Redis AOF persistence is enabled successfully
Need to enter the master node to write key value data
1.2 Check whether the key value is saved successfully in AOF
You need to enter the data directory, then find the file with the suffix incr.aof in the appendonlydir folder, and find sex and age in it
2. Turn off AOF persistence
First you need to turn off persistent storage in the redis-master.conf configuration file, and then restart the redis-master master node 
2.1 Verify that Redis AOF persistence is closed successfully
Need to enter the master node to write key value data
2.2 Check whether the key value is saved successfully in AOF
You need to enter the data directory, and then find the file with the suffix incr.aof in the appendonlydir folder, whether there are test123 and dcpp456
How to implement RDB storage in Redis!Scroll down
Note: RDB storage does not need to be turned on in the configuration file.
1. Go to the root directory of the redis-master container and find the dump.rdb file.View the file, it is empty
2. Use redis-cli to connect, enter password, and write data
3. After exiting the container with exit, check whether the data exists in the dump.rdb file in the root directory
4, even if dump.rdb is deleted in the data path of the container.Restart the redis-master master node.Then re-enter the container to view the data.Data will also exist.Because Redis data is stored in memory.
All right!The AOF and RDB persistence of Redis has been explained, and the next chapter will explain how Redis performs data migration
边栏推荐
- Golden Warehouse Database KingbaseGIS User Manual (6.10. Geometric Object Operation Operator)
- LeetCode刷题Top100之两数之和
- shell 脚本编程---入门
- 判断一个字符串是否为空,如果为空,对其赋值,如果不为空,获取字符的个数并打印第一个字符
- 每周推荐短视频:你常用的拍立淘,它的前身原来是这样的!
- 注解式编程小记
- Idea提升工作效率的必备技巧
- 总结:交叉验证
- Golden Warehouse Database KingbaseGIS User Manual (6.8. Geometry Object Input Function)
- MySQL事务的概念
猜你喜欢
随机推荐
基于TF-IDF 文本相似性实战 详细教程
阿里天池学习赛 新闻文本分类
Difference between @Resource and @Autowired
ESP8266 教程3 — 通过TCP组建局域网并通信
Configure checkstyle in IDEA
Django--20实现Redis支持、上下文以及上下文和接口的交互
ARM Architecture 4: Embedded Hardware Platform Interface Development
Sub-database sub-table ShardingSphere-JDBC notes arrangement
第二篇 DS5 Armv8 样例工程报错之GCC编译
[Embedded open source library] The use of cJSON, an efficient and streamlined json parsing library
分库分表之sharding-proxy
(三)Redis 如何进行压测
Trilium使用总结
2022 building welder (building a special type of work) examination questions and simulation test
Tips to improve your productivity, you have to know - Navitcat shortcuts
4 Module 3: Literature Reading and Research Methods
UML基本概念——动态视图
HAVE FUN | "SOFA Planet" spacecraft plan, the latest progress of source code analysis activities
Keras与tensorflow 使用基础
【Redis】Redis 的安装及图形化界面 Redis DeskTop Manager 的安装与使用



















