且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

redis 导出导入详解

更新时间:2022-10-04 11:41:17

1,安装redis-dump

查看复制打印?

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

  2.   

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

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

  5.   

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

2,redis-dump导出数据

查看复制打印?

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

  2. Trying 127.0.0.1...  

  3. Connected to 127.0.0.1.  

  4. Escape character is '^]'.  

  5. set test 11 //设置一个值  

  6. +OK  

  7. get test //取值  

  8. $2  

  9. 11  

  10.   

  11. [root@localhost tank]# redis-dump -u 127.0.0.1:6379 >test.json //导出数据  

3,redis-load还原数据

查看复制打印?

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

  2. Trying 127.0.0.1...  

  3. Connected to 127.0.0.1.  

  4. Escape character is '^]'.  

  5. flushall //请空所有数据  

  6. +OK  

  7. keys * //查看已清空  

  8. *0  

  9.   

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

  11.   

  12. [root@localhost tank]# telnet 127.0.0.1 6379  

  13. Trying 127.0.0.1...  

  14. Connected to 127.0.0.1.  

  15. Escape character is '^]'.  

  16. keys * //已导入成功  

  17. *1  

  18. $4  

  19. test  

 











本文转自 chengxuyonghu 51CTO博客,原文链接:http://blog.51cto.com/6226001001/1896508,如需转载请自行联系原作者