Redis-RedisShake数据迁移工具
一、什么是 RedisShake
RedisShake 是一个用于处理和迁移 Redis 数据的工具,它提供以下特性:
- Redis 兼容性:RedisShake 兼容从 2.8 到 7.2 的 Redis 版本,并支持各种部署方式,包括单机,主从,哨兵和集群。
- 云服务兼容性:RedisShake 与主流云服务提供商提供的流行 Redis-like 数据库无缝工作,包括但不限于:
- 阿里云-云数据库 Redis 版
- 阿里云-云原生内存数据库Tair
- AWS - ElastiCache
- AWS - MemoryDB
- Module 兼容:RedisShake 与 TairString,TairZSet 和 TairHash 模块兼容。
- 多种导出模式:RedisShake 支持 PSync,RDB 和 Scan 导出模式。
- 数据处理:RedisShake 通过自定义脚本实现数据过滤和转换。
二、安装部署
参考文档:快速上手 | RedisShake
# 下载包地址
https://github.com/tair-opensource/RedisShake/releases$ tar -xf redis-shake-linux-amd64.tar.gz$ cd redis_shake# 主要配置以下内容
vim shake.toml
[sync_reader] //源端
cluster = true # set to true if source is a redis cluster
address = "192.162.33.6:7001" # when cluster is true, set address to one of the cluster node
username = "" # keep empty if not using ACL
password = "F2r?ria2da71O63" # 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[redis_writer] //目的端
cluster = true # 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.162.33.123:7001" # when cluster is true, set address to one of the cluster node
username = "" # keep empty if not using ACL
password = "F2r?ri7?eraz171O63" # keep empty if no authentication is required
tls = false
off_reply = false # ture off the server reply# 启动命令
$ ./redis-shake shake.toml
三、数据验证
在增量同步阶段经常需要判断源端与目标端数据是否一致,介绍两种经验方法:
- 通过日志或者监控,观察到 RedisShake 的同步流量为 0,认为同步结束,两端一致。
- 对比源端与目的端 Key 数量是否相等,如果相等,认为一致。
如果 Key 带有过期时间,会导致 Key 数量不一致。原因:
- 因为过期算法限制,源端中可能存在一些 Key 已经过期但实际上没有被删除,这批 Key 在目的端可能会被删除,导致目的端 Key 数量少于源端。
- 源端和目的端独立运行,各自的过期算法独立运行,过期算法具有随机性,会导致源端和目的端删除的 Key 不一致,导致 Key 数量不一致。
在实践中,带有过期时间的 Key 一般认为是允许不一致的,不会影响业务,所以可以仅校验不带有过期时间的 Key 数量是否一致。如下所示,应当分别计算源端和目的端的 $keys-$expires
的值是否一样。
127.0.0.1:7001> info keyspace
# Keyspace
db0:keys=4463175,expires=2,avg_ttl=333486
四、跨版本迁移参考:
跨版本迁移 | RedisShake