栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 数据库 > 缓存机制 > Redis缓存

Redis migrate数据迁移工具的使用教程

Redis缓存 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Redis migrate数据迁移工具的使用教程

前言

在工作中可能会遇到单点Redis向Redis集群迁移数据的问题,但又不能老麻烦运维来做。为了方便研发自己迁移数据,我这里写了一个简单的Redis迁移工具,希望对有需要的人有用。

本工具支持:

  • 单点Redis到单点Redis迁移
  • 单点Redis到Redis集群迁移
  • Redis集群到Redis集群迁移
  • Redis集群到单点Redis迁移

该工具已经编译成了多平台命令,直接从Github下载二进制文件执行就好了。

项目地址: https://github.com/icowan/redis-tool

把代码拉下来之后直接执行命令 make 就可以编译多个平台可执行文件,需要依赖golang编译器。

  • Windows amd64: redis-tool-windows-amd64.exe
  • MacOS amd64: redis-tool-darwin-amd64
  • Linux amd64: redis-tool-linux-amd64
  • Linux arm64: redis-tool-linux-arm64

查看使用方法:

$ chmod a+x redis-tool-linux-amd64
$ ./redis-tool-linux-amd64 -h

支持的数据类型

  • string 字符串
  • hash 散列列表
  • list 列表
  • sorted-set 有序集合

如何使用

下载好命令并授权之后执行 ./redis-tool-linux-amd64 -h 可以查看该工具所支持的所有功能:

$ ./redis-tool-darwin-amd64 migrate -h
数据迁移命令

Usage:
redis-tool migrate [command]

Examples:

支持命令:
[hash, set, sorted-set, list]


Available Commands:
all  迁移所有
hash 哈希列表迁移
list 列表迁移
 set  redis set 迁移
sorted-set 有序集合迁移

Flags:
 -h, --help   help for migrate
 --source-auth string 源密码
 --source-database int 源database
 --source-hosts string 源redis地址, 多个ip用','隔开 (default "127.0.0.1:6379")
 --source-prefix string 源redis前缀
 --source-redis-cluster 源redis是否是集群
 --target-auth string 目标密码
 --target-database int 目标database
 --target-hosts string 目标redis地址, 多个ip用','隔开 (default "127.0.0.1:6379")
 --target-prefix string 目标redis前缀
 --target-redis-cluster 目标redis是否是集群

Use "redis-tool migrate [command] --help" for more information about a command.

参数说明:

  • --source-auth: 源redis密码,如果有的话就填
  • --source-database: 源database,默认是 0
  • --source-hosts: 源redis地址, 集群的多个ip用','隔开 (default "127.0.0.1:6379")
  • --source-prefix: 源redis前缀, 可不填
  • --source-redis-cluster: 源redis是否是集群, 默认 false
  • --target-auth: 迁移目标redis密码,如果有的话就填
  • --target-database: 迁移目标database,默认是 0
  • --target-hosts: 迁移目标redis地址, 集群的多个ip用','隔开 (default "127.0.0.1:6379")
  • --target-prefix: 迁移目标redis前缀, 可不填
  • --target-redis-cluster: 迁移目标redis是否是集群, 默认 false

迁移单个key的数据

下面就举两个例子吧,其他的都差不太多。

Hash类型

可以通过命令 redis-tool migrate hash -h 查看使用说明

$ redis-tool migrate hash helloworld 
 --source-hosts 127.0.0.1:6379 
 --target-redis-cluster true 
 --target-hosts 127.0.0.1:6379,127.0.0.1:7379 
 --target-auth 123456

有序集合

可以通过命令 redis-tool migrate sorted-set -h 查看使用说明

有序集合的数据量可能会比较大,所以这里按 50000 为单位进行了切割。我这里测试过迁移近17000000万条的数据,用时40多分钟。

$ redis-tool migrate hash helloworld 
 --source-hosts 127.0.0.1:6379 
 --target-redis-cluster true 
 --target-hosts 127.0.0.1:6379,127.0.0.1:7379 
 --target-auth 123456

迁移所有key的数据支持通配符过滤

可以通过命令 redis-tool migrate all -h 查看使用说明

$ redis-tool migrate all "ipdetect:*"  
 --source-hosts 127.0.0.1:6379 
 --target-redis-cluster true 
 --target-hosts 127.0.0.1:6379,127.0.0.1:7379 
 --target-auth 123456

这个命令会编译匹配到的所有类型的key,再根据key的类型进行逐步迁移。

尾巴

使用golang写的一个比较简单的工具, 主要用于在Redis没有持久化或多套Redis向一套Redis迁移的情况下使用。

总结

到此这篇关于Redis migrate数据迁移工具的文章就介绍到这了,更多相关Redis migrate数据迁移工具内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/173305.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号