当前位置: 首页 > 工具软件 > Redis-Dump > 使用案例 >

【学习笔记】redis 常见的导出导入之redis-dump

梅欣然
2023-12-01

一、简介

本文主要介绍如何通过redis-dump工具实现redis数据的导入导出,导出的文件为json文件,导出后可自行编辑,重新导入原redis或其他redis中。

二、redis-dump安装

1、配置rvm的sources地址

[root@docker ~]# yum install ruby rubygems ruby-devel -y
[root@docker ~]# gem sources --add http://gems.ruby-china.com/ --remove https://rubygems.org/
[root@docker ~]# gem sources -l
*** CURRENT SOURCES ***

http://gems.ruby-china.com/   #确定只剩这一个,因为通过配置国内的地址,可以避免下载速度问题

2、下载rvm

[root@docker ~]# curl -L get.rvm.io | bash -s stable   #可能要多试几次

3、如果出现以下情况,说明成功了一半:

[root@docker ~]# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0    101      0  0:00:01  0:00:01 --:--:--   101
100 24535  100 24535    0     0   4717      0  0:00:05  0:00:05 --:--:-- 12785
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: Signature made Sat 16 Jan 2021 02:46:22 AM CST using RSA key ID 39499BDB
gpg: Can't check signature: No public key
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.12.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

In case of further problems with validation please refer to https://rvm.io/rvm/security

4、先下载提示中的asc

[root@docker ~]# curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
[root@docker ~]# curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

5、然后接着下载rvm

[root@docker ~]# curl -L get.rvm.io | bash -s stable

6、source一下

[root@docker ~]# source /usr/local/rvm/scripts/rvm

7、下载安装ruby,这边直接安装2.7,安装2.2提示需要2.3,安装2.3提示需要2.4,安装2.4提示需要2.6,果断教程直接安排2.7

[root@docker ~]# rvm list known  #查看可安装版本信息
[root@docker ~]# rvm install 2.7 

8、安装redis-dump

[root@docker ~]# gem install redis-dump

三、redis导入导出

1、导出

### 例如: redis-dump -u:123456@10.10.1.10:6379 > test.json
[root@docker ~]# redis-dump -u:passwrd@ip:端口 > test.json

2、导入

### 例如: < test.json redis-load -n -u 10.10.1.10:6379 -a 123456
 [root@docker ~]# < test.json redis-load -n -u ip:端口 -a passwrd
 ### -n 以二进制形式导入,避免一些格式问题导致导入失败
 类似资料: