redis的备份和还原,借助了第三方的工具,redis-dump

1、安装redis-dump

复制代码 代码如下:

[root@localhost tank]# yum install ruby rubygems ruby-devel   //安装rubygems 以及相关包 

[root@localhost tank]# gem sources -a http://ruby.taobao.org/   //源,加入淘宝,外面的源不能访问 

http://ruby.taobao.org/ added to sources 

[root@localhost tank]# gem install redis-dump -V   //安装redis-dump 

2、redis-dump导出数据

复制代码 代码如下:

[root@localhost tank]# telnet 127.0.0.1 6379 //telnet到redis 
Trying 127.0.0.1… 
Connected to 127.0.0.1. 
Escape character is ‘^]’. 
set test 11 //设置一个值 
+OK 
get test //取值 
$2 
11 
 
[root@localhost tank]# redis-dump -u 127.0.0.1:6379 >test.json //导出数据 

3、redis-load还原数据

复制代码 代码如下:

[root@localhost tank]# telnet 127.0.0.1 6379 //telnet到redis 

Trying 127.0.0.1… 

Connected to 127.0.0.1. 

Escape character is ‘^]’. 

flushall //请空所有数据 

+OK 

keys * //查看已清空 

*0 

 

[root@localhost tank]# < test.json redis-load //导入数据 

 

[root@localhost tank]# telnet 127.0.0.1 6379 

Trying 127.0.0.1… 

Connected to 127.0.0.1. 

Escape character is ‘^]’. 

keys * //已导入成功 

*1 

$4 

test 


声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。