redis的AOF恢复数据

  1. 启用AOF
  2. 使用AOF文件恢复数据

步骤一:启用AOF

bash 复制代码
127.0.0.1:6379> config set appendonly yes
OK
127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "yes"
127.0.0.1:6379> CONFIG rewrite
OK
[root@redis170 ~]# ls /var/lib/redis/
appendonly.aof  dump.rdb
[root@redis170 ~]# wc -l  /var/lib/redis/appendonly.aof
1 /var/lib/redis/appendonly.aof
[root@redis170 ~]# !redis
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> mset x 1 y 2 c 3
OK
127.0.0.1:6379> exit
[root@redis170 ~]# wc -l  /var/lib/redis/appendonly.aof
21 /var/lib/redis/appendonly.aof

步骤二:使用AOF文件恢复数据

bash 复制代码
1)备份aof文件
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "no"
127.0.0.1:6379> CONFIG set appendonly yes
OK
127.0.0.1:6379> exit
[root@redis170 ~]# ll /var/lib/redis/
总用量 8
-rw-r--r-- 1 redis redis 92 5月  24 11:35 appendonly.aof
-rw-r--r-- 1 redis redis 92 5月  24 11:34 dump.rdb
127.0.0.1:6379> mset x 1 y 2 z 3
OK
127.0.0.1:6379> keys *
1) "x"
2) "z"
3) "y"
127.0.0.1:6379> exit
[root@redis170 ~]# cp /var/lib/redis/appendonly.aof  /opt/
2)删除数据
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> keys *
1) "x"
2) "z"
3) "y"
127.0.0.1:6379> flushall
OK


3)恢复数据

[root@redis170 ~]# cp /opt/appendonly.aof  /var/lib/redis/
cp:是否覆盖'/var/lib/redis/appendonly.aof'? y
[root@redis170 ~]# systemctl start redis
[root@redis170 ~]# !redis
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> keys *
1) "z"
2) "y"
3) "x"
相关推荐
Jayyih1 小时前
嵌入式系统学习Day35(sqlite3数据库)
数据库·学习·sqlite
EkihzniY2 小时前
OCR 识别表现好坏离不开什么?
缓存
小熊h2 小时前
redis 集群——redis cluster(去中心化)
redis·去中心化
得意霄尽欢3 小时前
Redis之底层数据结构
数据结构·数据库·redis
hsjkdhs4 小时前
MySQL 数据类型与运算符详解
数据库·mysql
吐泡泡_5 小时前
Redis(集群)
redis
爱吃烤鸡翅的酸菜鱼5 小时前
【Redis】常用数据结构之Hash篇:从常用命令到使用场景详解
数据结构·数据库·redis·后端·缓存·哈希算法
Pretend° Ω5 小时前
LRU缓存详解:用C语言实现高效数据管理
运维·c语言·spring·缓存·lru·双向链表
李少兄5 小时前
IntelliJ IDEA 启动项目时配置端口指南
数据库·sql·intellij-idea
NineData5 小时前
NineData云原生智能数据管理平台新功能发布|2025年8月版
数据库·mongodb·云原生·数据库管理工具·ninedata·数据库迁移·数据复制