Redis数据迁移RedisShake的实现方法

 更新时间:2024年10月11日 11:22:18   作者:JAVA菜鸟程序员  
本文主要介绍了Redis数据迁移RedisShake的实现方法,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

一、基本功能

redis-shake它支持解析、恢复、备份、同步四个功能

恢复restore:将RDB文件恢复到目的redis数据库。

备份dump:将源redis的全量数据通过RDB文件备份起来。

解析decode:对RDB文件进行读取,并以json格式解析存储。

同步sync:支持源redis和目的redis的数据同步,支持全量和增量数据的迁移,支持单节点、主从版、集群版之间的互相同步。

同步rump:支持源redis和目的redis的数据同步,仅支持全量的迁移,采用scan和restore命令进行迁移,支持不同云厂商不同redis版本的迁移。

二、基本原理

三、RedisShake同步原理

1.源Redis服务实例相当于主库,Redis-shake相当于从库,它会发送psync指令给源Redis服务实例。

2.源Redis实例先把RDB文件传输给 Redis-shake ,Redis-shake 会把RDB文件发送给目的实例。

3.源实例会再把增量命令发送给 Redis-shake ,Redis-shake负责把这些增量命令再同步给目的实例。

四、RedisShake安装

确保您在本地机器上设置了 Golang 环境。

4.1、release包下载

Releases · tair-opensource/RedisShake · GitHub

4.2、解压

tar -zxvf redis-shake-linux-amd64.tar.gz -C /home/redisshake/

解压完了之后有两个文件:

4.3、修改shake.toml配置文件

function = ""


[sync_reader]
cluster = false            # set to true if source is a redis cluster
address = "127.0.0.1:6379" # when cluster is true, set address to one of the cluster node
username = ""              # keep empty if not using ACL
password = ""              # keep empty if no authentication is required
tls = false
sync_rdb = true # set to false if you don't want to sync rdb
sync_aof = true # set to false if you don't want to sync aof
prefer_replica = true # set to true if you want to sync from replica node

#[scan_reader]
#cluster = false            # set to true if source is a redis cluster
#address = "127.0.0.1:6379" # when cluster is true, set address to one of the cluster node
#username = ""              # keep empty if not using ACL
#password = ""              # keep empty if no authentication is required
#tls = false
#dbs = []                   # set you want to scan dbs such as [1,5,7], if you don't want to scan all
#scan = true                # set to false if you don't want to scan keys
#ksn = false                # set to true to enabled Redis keyspace notifications (KSN) subscription
#count = 1                  # number of keys to scan per iteration

# [rdb_reader]
# filepath = "/tmp/dump.rdb"

# [aof_reader]
# filepath = "/tmp/.aof"
# timestamp = 0              # subsecond

[redis_writer]
cluster = false            # set to true if target is a redis cluster
sentinel = false           # set to true if target is a redis sentinel
master = ""                # set to master name if target is a redis sentinel
address = "192.168.72.129:6379" # when cluster is true, set address to one of the cluster node
username = ""              # keep empty if not using ACL
password = ""              # keep empty if no authentication is required
tls = false
off_reply = false       # ture off the server reply

[advanced]
dir = "data"
ncpu = 0        # runtime.GOMAXPROCS, 0 means use runtime.NumCPU() cpu cores
pprof_port = 0  # pprof port, 0 means disable
status_port = 0 # status port, 0 means disable

# log
log_file = "shake.log"
log_level = "info"     # debug, info or warn
log_interval = 5       # in seconds

# redis-shake gets key and value from rdb file, and uses RESTORE command to
# create the key in target redis. Redis RESTORE will return a "Target key name
# is busy" error when key already exists. You can use this configuration item
# to change the default behavior of restore:
# panic:   redis-shake will stop when meet "Target key name is busy" error.
# rewrite: redis-shake will replace the key with new value.
# ignore:  redis-shake will skip restore the key when meet "Target key name is busy" error.
rdb_restore_command_behavior = "panic" # panic, rewrite or skip

# redis-shake uses pipeline to improve sending performance.
# This item limits the maximum number of commands in a pipeline.
pipeline_count_limit = 1024

# Client query buffers accumulate new commands. They are limited to a fixed
# amount by default. This amount is normally 1gb.
target_redis_client_max_querybuf_len = 1024_000_000

# In the Redis protocol, bulk requests, that are, elements representing single
# strings, are normally limited to 512 mb.
target_redis_proto_max_bulk_len = 512_000_000

# If the source is Elasticache or MemoryDB, you can set this item.
aws_psync = "" # example: aws_psync = "10.0.0.1:6379@nmfu2sl5osync,10.0.0.1:6379@xhma21xfkssync"

# destination will delete itself entire database before fetching files
# from source during full synchronization.
# This option is similar redis replicas RDB diskless load option:
#   repl-diskless-load on-empty-db
empty_db_before_sync = false

[module]
# The data format for BF.LOADCHUNK is not compatible in different versions. v2.6.3 <=> 20603
target_mbbloom_version = 20603

官方使用指导手册:Sync Reader | RedisShake

4.4、启动RediShake

./redis-shake shake.toml

4.5、测试数据迁移

在192.168.72.128这台机器上插入几个key

可以看到RedisShake工具在实施监听key,有新增的就会把新增的key迁移到另外一机器的redis中;看打印的日志是写了4条数据

在192.168.72.129这台机器上查看迁移的数据

4.6、数据校验

通过info keyspace命令,查看所有的key和过期key的数量。

到此这篇关于Redis数据迁移RedisShake的实现方法的文章就介绍到这了,更多相关Redis数据迁移RedisShake内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! 

您可能感兴趣的文章:

相关文章

  • Redis一键巡检脚本的实现

    Redis一键巡检脚本的实现

    在使用Redis作为数据存储的时候,定期进行巡检是非常重要的,本文主要介绍了Redis一键巡检脚本的实现,具有一定的参考价值,感兴趣的可以了解一下
    2024-06-06
  • Redis报错UnrecognizedPropertyException: Unrecognized field问题

    Redis报错UnrecognizedPropertyException: Unrecognized 

    在使用SpringBoot访问Redis时,报错提示识别不了属性headPart,经过排查,发现并非Serializable或getset方法问题,而是存在一个方法getHeadPart,但无headPart属性,解决方案是将getHeadPart改为makeHeadPart
    2024-10-10
  • Redis大key和多key拆分的解决方案

    Redis大key和多key拆分的解决方案

    大key会导致内存使用过高,多key可能导致查询效率低下,本文主要介绍了Redis大key和多key拆分的解决方案,具有一定的参考价值,感兴趣的可以了解一下
    2024-03-03
  • redis服务启动与停止方式

    redis服务启动与停止方式

    这篇文章主要介绍了redis服务启动与停止方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-01-01
  • Redis中的数据过期策略详解

    Redis中的数据过期策略详解

    这篇文章主要介绍了Redis中的数据过期策略,文中通过示例代码介绍的很详细,相信对大家的理解和学习具有一定的参考借鉴价值,有需要的朋友可以参考借鉴,下面来一起看看吧。
    2017-01-01
  • Windows下Redis x64的安装与使用教程详解

    Windows下Redis x64的安装与使用教程详解

    Redis是一款内存高速缓存数据库,可以满足我们对海量数据的读写需求,本文重点给大家介绍Windows下Redis x64的安装与使用教程,感兴趣的朋友一起看看吧
    2022-03-03
  • Redis做数据持久化的解决方案及底层原理

    Redis做数据持久化的解决方案及底层原理

    Redis有两种方式来实现数据的持久化,分别是RDB(Redis Database)和AOF(Append Only File),今天通过本文给大家聊一聊Redis做数据持久化的解决方案及底层原理,感兴趣的朋友一起看看吧
    2021-07-07
  • Redis中的bitmap详解

    Redis中的bitmap详解

    BitMap是通过一个bit位来表示某个元素对应的值或者状态,其中的key就是对应元素本身。我们知道8个bit可以组成一个Byte,所以bitmap本身会极大的节省储存空间,下面通过本文给大家介绍Redis中的bitmap知识,感兴趣的朋友一起看看吧
    2021-10-10
  • Redis实现用户关注的项目实践

    Redis实现用户关注的项目实践

    本文主要介绍了Redis实现用户关注的项目实践,通过使用Redis的set数据结构来存储关注对象,方便高效地进行添加和取消关注操作,具有一定的参考价值,感兴趣的可以了解一下
    2024-02-02
  • redis获取所有key的方法

    redis获取所有key的方法

    本文主要介绍了redis获取所有key的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-04-04

最新评论