redis 导出 导入 详解

借助了第三方的工具redis-dump

1,安装redis-dump

yum install ruby rubygems ruby-devel -y
gem sources --add http://gems.ruby-china.org/ --remove http://rubygems.org/

gem sources -l

apt-get intsall ruby-dev
gem install redis-dump -V 

redis-dump -u 127.0.0.1:6379 > db.json //导出数据
redis-load -u 127.0.0.1:6379 < test.json redis-load //导入数据

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 [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   redis-dump -u 127.0.0.1:6379 > db.json //导出数据 redis-load -u 127.0.0.1:6379 < 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

猜你喜欢

转载自blog.csdn.net/weixin_41010318/article/details/80651296
今日推荐