Redis移行データ移行ツール

作業中に、シングルポイント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

サポートされているデータタイプ

  • ストリング
  • ハッシュハッシュリスト
  • リストリスト
  • ソート済みセット順序付きセット

使い方

コマンドをダウンロードし、承認後に実行します。/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:source redis password、ある場合は入力します
  • --source-database:ソースデータベース、デフォルトは0
  • --source-hosts:ソースredisアドレス、クラスターの複数のipは「、」で区切られます(デフォルトは「127.0.0.1:6379」)
  • --source-prefix:ソースredisプレフィックス、オプション
  • --source-redis-cluster:ソースredisがクラスターであるかどうかに関係なく、デフォルトはfalseです
  • --target-auth:移行ターゲットredisパスワード、ある場合は入力します
  • --target-database:移行ターゲットデータベース、デフォルトは0
  • --target-hosts:移行ターゲットredisアドレス、クラスターの複数のipは「、」で区切られます(デフォルトは「127.0.0.1:6379」)
  • --target-prefix:移行ターゲットredisプレフィックス、オプション
  • --target-redis-cluster:移行ターゲットredisがクラスターであるかどうか、デフォルトはfalse

単一のキーのデータを移行します

ここに2つの例がありますが、他の例はそれほど違いはありません。

ハッシュタイプ

コマンドredis-toolmigrate 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移行データ移行ツール

注文セット

コマンドredis-toolmigratesorted-set -hを使用して、命令を表示できます
。順序付けられたセットのデータ量は比較的多い可能性があるため、50000単位でカットが実行されます。私は約1億7000万個のデータの移行をテストしましたが、これには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

Redis移行データ移行ツール

ワイルドカードフィルタリングをサポートするためにすべての主要データを移行する

コマンドredis-toolmigrate 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

このコマンドは、一致したすべてのキーをコンパイルしてから、キータイプに従って徐々に移行します。

golangで記述された比較的単純なツールで、主にRedisに永続性がない場合、または複数のRedisセットが1つのRedisセットに移行される場合に使用されます。

皆様のお役に立てれば幸いです、ありがとうございます!

著者:CreditEase Institute of Technology Cong

おすすめ

転載: blog.51cto.com/14159827/2545142