当前位置:网站首页>第五章:redis持久化,包括rdb和aof两种方式[通俗易懂]
第五章:redis持久化,包括rdb和aof两种方式[通俗易懂]
2022-08-05 10:04:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
rdb持久化方式:是在指定的时间写入硬盘
aof方式:是以日志,记录每一操作,
两个方式可以单独使用或结合使用
rdb
rdb方式是默认支持的。
特点:只有一个文件,根据配置文件的配置时间间隔,每个一段时间将数据统一读入到一个文件中,方便压缩转移。但是如果宕机就会丢失这段时间内的数据。
我们查看redis.conf配置文件:
有下面一段:
# like in the following example:
#
# save ""
save 900 1
save 300 10
save 60 10000
# By default Redis will stop accepting writes if RDB snapshots are enabled
save 900 1 是指,每900秒内有一个key发生变化就持久化一次
save 300 10:每300秒内有10个key发生变化就持久化一次
save 60 10000:每60秒内有10000个key发生变化就持久化一次
这是分为三种持久化策略,尽可能的包装数据安全又能减少保持文件的数量。
redis.conf往下有如下:
# The filename where to dump the DB
dbfilename dump.rdb
# The working directory.
则是默认文件的名称;
在往下:
# Note that you must specify a directory here, not a file name.
dir ./
这是rdb在配置文件的同级目录下。我的在home目录下:
这里我们测试下,在客户端我的key是有前面我们学习创建的:
下面我先退出客户端和服务,然后dump.rdb文件删掉,再重启服务:
127.0.0.1:6379> shutdow
(error) ERR unknown command 'shutdow'
127.0.0.1:6379> shutdown
not connected> exit
[email protected]:~$ ./redis/src/redis-server
[email protected]:~$ ./redis/src/redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>
发现没有值了。这里我们再添加几条数据:
127.0.0.1:6379> set n1 aa
OK
127.0.0.1:6379> set n2 bb
OK
127.0.0.1:6379> keys *
1) "n2"
2) "n1"
127.0.0.1:6379> shutdown save
not connected> exit
然后我们会看到redis目录下会自动生成一条dump.rdb文件:
然后我们再启动redis服务的时候,会执行rdb check验证,然后加载redis目录下rdb文件;加载数据:
127.0.0.1:6379> keys *
1) "n1"
2) "n2"
127.0.0.1:6379>
我们刚加的是有的。
如果把rdb剪切到其他目录,也就是不是redis.conf文件配置的默认目录下,看看能不能用。这样肯定是不行的。这里就不演示了。如果在剪切回来发现又数据了。
下面测试aof方式
AOF方式:以日志的方式一条一条数据的记录下来,每生成一条数据就记录下来。
到redis.conf文件下看看配置:
这里appendonly no 表示默认aof方式为关闭,我们这里改为开启
下面一行是默认的文件名。
我们继续往下看看redis.conf文件看看aof的保存策略:
always是只要发生修改就立即同步,推荐使用,安全性高。
everysec是每秒同步一次。
这里我们改为只要发生修改就同步一次:
然后我们重启redis服务:
下面小编出了点问题,没有实验成功,暂且放这里
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106131.html原文链接:https://javaforall.cn
边栏推荐
- PAT Grade B-B1020 Mooncake(25)
- Introduction to SD NAND Flash!
- 21 Days of Deep Learning - Convolutional Neural Networks (CNN): Weather Recognition (Day 5)
- 首次去中心化抢劫?近2亿美元损失:跨链桥Nomad 被攻击事件分析
- Technical dry goods | Hausdorff distance for image segmentation based on MindSpore
- Handwriting Currying - toString Comprehension
- LeetCode 216. Combined Sum III (2022.08.04)
- First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
- EU | Horizon 2020 ENSEMBLE: D2.13 SOTIF Safety Concept (Part 2)
- Bias lock/light lock/heavy lock lock is healthier. How is locking and unlocking accomplished?
猜你喜欢
【温度预警程序de开发】事件驱动模型实例运用
入门 Polkadot 平行链开发,看这一篇就够了
IDEA执行Test操作导致数据插入时出现了重复数据
电竞、便捷、高效、安全,盘点OriginOS功能的关键词
three objects are arranged in a spherical shape around the circumference
蚁剑webshell动态加密连接分析与实践
three.js debugging tool dat.gui use
Open Source Summer | How OpenHarmony Query Device Type (eTS)
还在找网盘资源吗?快点收藏如下几个值得收藏的网盘资源搜索神器吧!
three.js调试工具dat.gui使用
随机推荐
企业的数字化转型到底是否可以买来?
为什么sys_class 里显示的很多表的 RELTABLESPACE 值为 0 ?
无题二
js graphics operation one (compatible with pc, mobile terminal to achieve draggable attribute drag and drop effect)
Oracle临时表空间作用
Oracle temporary table space role
Brief Analysis of WSGI Protocol
STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
2022华数杯数学建模A题环形振荡器的优化设计思路思路代码分享
2022.8.3
mysql索引
Jenkins使用手册(2) —— 软件配置
EU | Horizon 2020 ENSEMBLE: D2.13 SOTIF Safety Concept (Part 2)
19. Server-side session technology Session
语音社交软件开发——充分发挥其价值
歌词整理
【AGC】增长服务1-远程配置示例
The JVM collection that Alibaba's top architects have summarized for many years, where can't I check it!
MySQL transactions
正则表达式replaceAll()方法具有什么功能呢?