当前位置:网站首页>第五章: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
边栏推荐
- [Office] Collection of Microsoft Office download addresses (offline installation and download of Microsoft's official original version)
- js graphics operation one (compatible with pc, mobile terminal to achieve draggable attribute drag and drop effect)
- Keil升级到AC6后,到底有哪些变化?
- 使用工具类把对象中的null值转换为空字符串(集合也可以使用)
- STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
- Microservice Technology Stack
- NowCoderTOP35-40——持续更新ing
- 还在找网盘资源吗?快点收藏如下几个值得收藏的网盘资源搜索神器吧!
- 企业的数字化转型到底是否可以买来?
- IDEA执行Test操作导致数据插入时出现了重复数据
猜你喜欢
JS逆向入门学习之回收商网,手机号码简易加密解析
皕杰报表的下拉框联动
Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
IDEA执行Test操作导致数据插入时出现了重复数据
Jenkins manual (2) - software configuration
egg框架使用(一)
NowCoderTOP35-40——持续更新ing
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
百年北欧奢华家电品牌ASKO智能三温区酒柜臻献七夕,共品珍馐爱意
随机推荐
长达四年的减肥记录
无题七
Tanabata romantic date without overtime, RPA robot helps you get the job done
Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)
阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!
【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different
Can MySQL use aggregate functions without GROUP BY?
The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf
无题五
公众号如何运维?公众号运维专业团队
uniapp 连接ibeacon
无题九
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
Complete image segmentation efficiently based on MindSpore and realize Dice!
IDEA performs the Test operation, resulting in duplicate data when data is inserted
创建一个 Dapp,为什么要选择波卡?
开源一夏|OpenHarmony如何查询设备类型(eTS)
egg框架使用(一)
After Keil upgrades to AC6, what changes?
dotnet OpenXML 解析 PPT 图表 面积图入门