当前位置:网站首页>(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
边栏推荐
- Four functional interfaces
- HAVE FUN | “SOFA 星球”飞船计划、源码解析活动最新进展
- Redis - Data Types (Basic Instructions, String, List, Set, Hash, ZSet, BitMaps, HyperLogLog, GeoSpatial) / Publish and Subscribe
- Delphi7学习记录-demo实例
- 每周推荐短视频:你常用的拍立淘,它的前身原来是这样的!
- JedisLock_Redis分布式锁实现_转载
- 2022煤矿瓦斯检查考试题模拟考试题库及答案
- 【嵌入式开源库】使用J-Link打印日志,让你节省一个打印串口
- 分库分表之sharding-proxy
- guava RateLimiter uniform current limit
猜你喜欢
随机推荐
总结:交叉验证
每周推荐短视频:你常用的拍立淘,它的前身原来是这样的!
UML基本概念——动态视图
基于 TF-IDF 文本匹配实战详细教程 数据+代码 可直接运行
DS220702-0707作业
Four functional interfaces
Idea 2021.3.3版本文件目录展开
关于ie下href有中文出现RFC 7230 and RFC 3986问题的研究
【无2022上海市安全员A证考试题库及模拟考试
MySQL事务的概念
Weekly recommended short video: your commonly used Polaroid, its predecessor turned out to be like this!
leetcode 9. Palindromic Numbers
nodes服务器
HAVE FUN | "SOFA Planet" spacecraft plan, the latest progress of source code analysis activities
Switch and Router Technology - 32 - Named ACL
(二)Docker安装Redis实战(持久化AOF和RDB快照)
提升你工作效率的技巧,你得知道——Navitcat 快捷键
让你代码越来越高大上的技巧——代码规范,你得知道
代理模式(简要介绍)
Redis-使用jedis连接linux中redis服务器失败的解决方案



















