edis的備份與還原,藉助了第三方的工具,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 |