首页 > 数据库 > redis > redis导入导出
2017
06-22

redis导入导出

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

[root@localhost tank]# yum install ruby rubygems ruby-devel   //安装rubygems 以及相关包  
 
[root@localhost tank]# gem sources -a https://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 10.10.121.23:6379 //telnet到redis  
Trying 10.10.121.23...  
Connected to 10.10.121.23.  
Escape character is '^]'.  
set test 11 //设置一个值  
+OK  
get test //取值  
$2  
11  
[root@localhost tank]#redis-dump -u 10.10.121.23:6379 >test.josn

3,redis-load还原数据

[root@localhost tank]# telnet 10.10.121.23 6379 //telnet到redis  
Trying 10.10.121.23...  
Connected to 10.10.121.23.  
Escape character is '^]'.  
flushall //请空所有数据  
+OK  
keys * //查看已清空  
*0  
 
[root@localhost tank]#  <test.josn redis-load -u 10.10.121.23:6379 //导入数据  
 
[root@localhost tank]# telnet 10.10.121.23 6379  
Trying 10.10.121.23...  
Connected to 10.10.121.23.  
Escape character is '^]'.  
keys * //已导入成功  
*1  
$4  
test
最后编辑:
作者:saunix
大型互联网公司linux系统运维攻城狮,专门担当消防员