redis-shake工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.5 KiB

# redis-shake
6 years ago
[![CI](https://github.com/alibaba/RedisShake/actions/workflows/ci.yml/badge.svg?branch=v3)](https://github.com/alibaba/RedisShake/actions/workflows/ci.yml)
2 years ago
- [中文文档](./README_zh.md)
2 years ago
redis-shake is a tool for Redis data migration and data filtering.
2 years ago
## Feature
2 years ago
* ⚡ High performance
2 years ago
* ✅ Tested on Redis 5.0, Redis 6.0 and Redis 7.0
2 years ago
* 🤗 Support custom filtering rules using lua
* 💪 Support large instance migration
* 💖 Support `restore` mode and `sync` mode
* Support Aliyun Redis and ElastiCache
For older versions of redis-shake (support codis, twemproxy) please visit [here](https://github.com/alibaba/RedisShake/tree/develop).
![redis-shake2.PNG](https://s2.loli.net/2022/07/10/OZrSGutknlI8XNp.png)
6 years ago
![image.png](https://s2.loli.net/2022/06/30/vU346lVBrNofKzu.png)
2 years ago
# Document
6 years ago
2 years ago
## Install
6 years ago
2 years ago
### Binary package
6 years ago
2 years ago
Download from Release: [https://github.com/alibaba/RedisShake/releases](https://github.com/alibaba/RedisShake/releases)
2 years ago
### Compile from source
2 years ago
After downloading the source code, run the `sh build.sh` command to compile.
```shell
2 years ago
git clone https://github.com/alibaba/RedisShake
cd RedisShake
sh build.sh
```
2 years ago
## Usage
1. Edit `redis-shake.toml` or `restore.toml` and modify the source and target configuration items in it.
2 years ago
2. Start redis-shake.
```shell
./bin/redis-shake redis-shake.toml
# or
./bin/redis-shake restore.toml
```
2 years ago
3. Check data synchronization status.
6 years ago
2 years ago
## Configure
2 years ago
The redis-shake configuration file refers to `redis-shake.toml` or `restore.toml`.
6 years ago
2 years ago
## Data filtering
2 years ago
redis-shake supports custom filtering rules using lua scripts. redis-shake can be started with
the following command:
```shell
./bin/redis-shake redis-shake.toml filter/xxx.lua
```
2 years ago
Some following filter templates are provided in `filter` directory:
2 years ago
1. `filter/print.lua`:print all commands
2. `filter/swap_db.lua`:swap the data of db0 and db1
2 years ago
### Custom filter rules
6 years ago
2 years ago
Refer to `filter/print.lua` to create a new lua script, and implement the filter function in the lua script. The
arguments of the function are:
2 years ago
- id: command id
- is_base: is the command read from the dump.rdb file
- group: command group, see the description file
under [redis/src/commands](https://github.com/redis/redis/tree/unstable/src/commands)
- cmd_name: command name
- keys: keys in command
- slots: slots in command
- db_id: database id
- timestamp_ms: timestamp of the command in milliseconds. The current version does not support it.
2 years ago
The return value is:
- code
2 years ago
- 0: allow this command to pass
- 1: this command is not allowed to pass
- 2: this command should not appear, and let redis-shake exit with an error
- db_id: redirected db_id
2 years ago
# Contribution
2 years ago
## Lua script
2 years ago
Welcome to share more creative lua scripts.
2 years ago
1. Add lua scripts under `filters/`.
2. Add description to `README.md`.
3. Submit a pull request.
2 years ago
## Redis Module support
6 years ago
2 years ago
1. Add code under `internal/rdb/types`.
2. Add a command file under `scripts/commands`, and use the script to generate a `table.go` file and move it to
the `internal/commands` directory.
3. Add test cases under `test/cases`.
4. Submit a pull request.
6 years ago
# 感谢
6 years ago
redis-shake 旧版是阿里云基于豌豆荚开源的 redis-port 进行二次开发的一个支持 Redis 异构集群实时同步的工具。
redis-shake v3 在 redis-shake 旧版的基础上重新组织代码结构,使其更具可维护性的版本。
6 years ago
redis-shake v3 参考借鉴了以下项目:
- https://github.com/HDT3213/rdb
- https://github.com/sripathikrishnan/redis-rdb-tools