Redis教程

redis-dump

本文主要是介绍redis-dump,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

环境:
OS:Centos 7
ip:192.168.1.135
redis服务器:192.168.1.49

1.安装ruby
下载地址
https://www.ruby-lang.org/en/downloads/
我这里下载的是2.7.5
ruby-2.7.5.tar.gz

 

2.安装
[root@localhost soft]#tar -zxvf ruby-2.7.5.tar.gz
[root@localhost soft]#cd ruby-2.7.5
[root@localhost ruby-2.7.5]#./configure
[root@localhost ruby-2.7.5]#make
[root@localhost ruby-2.7.5]#make install
[root@localhost ruby-2.7.5]# ruby -v
若之前有安装ruby的,可以指向刚才安装的新的版本
[root@localhost ruby-2.7.5]#ln -s /usr/local/bin/ruby /usr/bin/ruby
[root@localhost ruby-2.7.5]#ln -s /usr/local/bin/gem /usr/bin/gem
ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]

3.安装redis-dump
[root@localhost soft]#gem install redis-dump -V


4.导出
redis-dump --uri=redis://192.168.1.49:6379 --password=123>/tmp/redis49.json

 

发现导出集群模式报错误,不知道是不是给软件不支持导出集群的redis
CROSSSLOT Keys in request don't hash to the same slot

各参数说明:
[root@localhost ruby-2.7.5]# redis-dump -h
Try: /usr/local/rvm/gems/ruby-2.4.1/bin/redis-dump show-commands
Usage: /usr/local/rvm/gems/ruby-2.4.1/bin/redis-dump [global options] COMMAND [command options]
-u, --uri=S Redis URI (e.g. redis://hostname[:port])
-d, --database=S Redis database (e.g. -d 15)
-a, --password=S Redis password (e.g. -a 'my@pass/word')
-s, --sleep=S Sleep for S seconds after dumping (for debugging)
-c, --count=S Chunk size (default: 10000)
-f, --filter=S Filter selected keys (passed directly to redis' KEYS command)
-b, --base64 Encode key values as base64 (useful for binary values)
-O, --without_optimizations Disable run time optimizations
-V, --version Display version
-D, --debug
--nosafe

 

5.尝试将redis清空掉
redis服务器操作
我这里将redis的aof文件和rdb文件删除掉,然后重新启动redis
关闭
/usr/local/services/redis/bin/redis-cli -h 192.168.1.49 -a 123456 -p 6379 shutdown

[root@]# rm appendonly.aof
[root@]# rm dump.rdb
重新启动
[root@]# /usr/local/services/redis/bin/redis-server /home/middle/redis/conf/6379.conf

登陆
[root@]# /usr/local/services/redis/bin/redis-cli -h 192.168.1.49 -a 123456 -p 6379
可以查看之前的key是否存在,这个时候之前的key是没有了的,下面进行恢复

 

6.导入
[root@localhost ruby-2.7.5]#cat /tmp/redis49.json | redis-load --uri=redis://192.168.1.49:6379 --password=yeemiao123
该命令参数说明
[root@localhost tmp]# redis-load -h
Try: /usr/local/rvm/gems/ruby-2.4.1/bin/redis-load show-commands
Usage: /usr/local/rvm/gems/ruby-2.4.1/bin/redis-load [global options] COMMAND [command options]
-u, --uri=S Redis URI (e.g. redis://hostname[:port])
-d, --database=S Redis database (e.g. -d 15)
-a, --password=S Redis password (e.g. -a 'my@pass/word')
-s, --sleep=S Sleep for S seconds after dumping (for debugging)
-b, --base64 Decode key values from base64 (used with redis-dump -b)
-n, --no_check_utf8
-V, --version Display version
-D, --debug
--nosafe

 

这篇关于redis-dump的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!