濮阳杆衣贸易有限公司

主頁 > 知識庫 > Redis migrate數(shù)據(jù)遷移工具的使用教程

Redis migrate數(shù)據(jù)遷移工具的使用教程

熱門標簽:四川穩(wěn)定外呼系統(tǒng)軟件 臺灣電銷 南京手機外呼系統(tǒng)廠家 廊坊外呼系統(tǒng)在哪買 地圖標注工廠入駐 一個地圖標注多少錢 400電話辦理的口碑 b2b外呼系統(tǒng) 高碑店市地圖標注app

前言

在工作中可能會遇到單點Redis向Redis集群遷移數(shù)據(jù)的問題,但又不能老麻煩運維來做。為了方便研發(fā)自己遷移數(shù)據(jù),我這里寫了一個簡單的Redis遷移工具,希望對有需要的人有用。

本工具支持:

  • 單點Redis到單點Redis遷移
  • 單點Redis到Redis集群遷移
  • Redis集群到Redis集群遷移
  • Redis集群到單點Redis遷移

該工具已經(jīng)編譯成了多平臺命令,直接從Github下載二進制文件執(zhí)行就好了。

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

把代碼拉下來之后直接執(zhí)行命令 make 就可以編譯多個平臺可執(zhí)行文件,需要依賴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

支持的數(shù)據(jù)類型

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

如何使用

下載好命令并授權(quán)之后執(zhí)行 ./redis-tool-linux-amd64 -h 可以查看該工具所支持的所有功能:

$ ./redis-tool-darwin-amd64 migrate -h
數(shù)據(jù)遷移命令

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.

參數(shù)說明:

  • --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的數(shù)據(jù)

下面就舉兩個例子吧,其他的都差不太多。

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 查看使用說明

有序集合的數(shù)據(jù)量可能會比較大,所以這里按 50000 為單位進行了切割。我這里測試過遷移近17000000萬條的數(shù)據(jù),用時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的數(shù)據(jù)支持通配符過濾

可以通過命令 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,再根據(jù)key的類型進行逐步遷移。

尾巴

使用golang寫的一個比較簡單的工具, 主要用于在Redis沒有持久化或多套Redis向一套Redis遷移的情況下使用。

總結(jié)

到此這篇關(guān)于Redis migrate數(shù)據(jù)遷移工具的文章就介紹到這了,更多相關(guān)Redis migrate數(shù)據(jù)遷移工具內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 從MySQL到Redis的簡單數(shù)據(jù)庫遷移方法
  • Redis數(shù)據(jù)導(dǎo)入導(dǎo)出以及數(shù)據(jù)遷移的4種方法詳解
  • php實現(xiàn)redis數(shù)據(jù)庫指定庫號遷移的方法
  • Redis源碼解析:集群手動故障轉(zhuǎn)移、從節(jié)點遷移詳解

標簽:南寧 拉薩 泰州 伊春 定州 畢節(jié) 甘南 河源

巨人網(wǎng)絡(luò)通訊聲明:本文標題《Redis migrate數(shù)據(jù)遷移工具的使用教程》,本文關(guān)鍵詞  Redis,migrate,數(shù)據(jù),遷移,工具,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Redis migrate數(shù)據(jù)遷移工具的使用教程》相關(guān)的同類信息!
  • 本頁收集關(guān)于Redis migrate數(shù)據(jù)遷移工具的使用教程的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    岳普湖县| 利辛县| 云霄县| 丰原市| 通州市| 仁化县| 揭西县| 普宁市| 信丰县| 峡江县| 自治县| 南昌市| 寻甸| 东兴市| 德江县| 新兴县| 浦东新区| 巴青县| 三江| 平度市| 兖州市| 安顺市| 丁青县| 南雄市| 抚远县| 文成县| 突泉县| 黔东| 台南市| 阿瓦提县| 沙田区| 共和县| 渭源县| 洪江市| 高邮市| 秦安县| 肇庆市| 澳门| 绿春县| 磐安县| 韩城市|