Redis所有数据都是保存在内存中,Redis数据备份可以定期的通过异步方式保存到磁盘上,该方式称为半持久化模式,如果每一次数据变化都写入aof文件里面,则称为全持久化模式。同时还可以基于Redis主从复制实现Redis备份与恢复。
[root@k8s-master1 bin]# ./redis-cli -h 192.168.210.85 -p 6379
Master85:
192.168.210.85:6379> info replication
# Replication
role:master
connected_slaves:0
master_replid:145346920da531a82dd62c0b7130c9ea48e8101f
master_replid2:982b93c14b73dda8088029b664f377361fa5e7b9
master_repl_offset:503252
second_repl_offset:497019
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:338764
repl_backlog_histlen:164489
192.168.210.85:6379> set k1 v1
OK
192.168.210.85:6379> set k2 v2
OK
192.168.210.85:6379> set k3 v3
OK
192.168.210.85:6379> set k4 v4
OK
192.168.210.85:6379> get k1
"v1"
192.168.210.85:6379> get k2
"v2"
192.168.210.85:6379> get k3
"v3"
192.168.210.85:6379> get k4
"v4"
192.168.210.85:6379> SAVE
OK
Slave177
192.168.210.177:6379> get k1
"v1"
192.168.210.177:6379> get k2
"v2"
192.168.210.177:6379> get k3
"v3"
192.168.210.177:6379> get k4
"v4"
192.168.210.85:6379> CONFIG GET dir
1) "dir"
2) "/data/redis"
以上命令 CONFIG GET dir 输出的 redis 备份目录为 /
192.168.210.85:6379> shutdown
not connected> exit
[root@k8s-master1 bin]# ./redis-cli -h 192.168.210.85 -p 6379
Could not connect to Redis at 192.168.210.85:6379: Connection refused
not connected>
重启85服务器主节点切换到177服务器,切换到master
[root@k8s-master1 bin]# ./redis-cli -h 192.168.210.85 -p 6379
192.168.210.85:6379> DBSIZE
(integer) 4
192.168.210.85:6379> keys *
1) "k4"
2) "k1"
3) "k2"
4) "k3"
相关阅读:
1、Redis搭建哨兵
2、Redis搭建和主从复制
3、Redis配置文件详细总结
4、Redis常用数据类型
5、Redis三主三从集群
6、欢迎加入技术交流