Redis migrate數(shù)據(jù)遷移工具的使用教程
前言
在工作中可能會(huì)遇到單點(diǎn)Redis向Redis集群遷移數(shù)據(jù)的問(wèn)題,但又不能老麻煩運(yùn)維來(lái)做。為了方便研發(fā)自己遷移數(shù)據(jù),我這里寫(xiě)了一個(gè)簡(jiǎn)單的Redis遷移工具,希望對(duì)有需要的人有用。
本工具支持:
- 單點(diǎn)Redis到單點(diǎn)Redis遷移
- 單點(diǎn)Redis到Redis集群遷移
- Redis集群到Redis集群遷移
- Redis集群到單點(diǎn)Redis遷移
該工具已經(jīng)編譯成了多平臺(tái)命令,直接從Github下載二進(jìn)制文件執(zhí)行就好了。
項(xiàng)目地址: https://github.com/icowan/redis-tool
把代碼拉下來(lái)之后直接執(zhí)行命令 make 就可以編譯多個(gè)平臺(tái)可執(zhí)行文件,需要依賴(lài)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ù)類(lèi)型
- 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地址, 多個(gè)ip用','隔開(kāi) (default "127.0.0.1:6379") --source-prefix string 源redis前綴 --source-redis-cluster 源redis是否是集群 --target-auth string 目標(biāo)密碼 --target-database int 目標(biāo)database --target-hosts string 目標(biāo)redis地址, 多個(gè)ip用','隔開(kāi) (default "127.0.0.1:6379") --target-prefix string 目標(biāo)redis前綴 --target-redis-cluster 目標(biāo)redis是否是集群 Use "redis-tool migrate [command] --help" for more information about a command.
參數(shù)說(shuō)明:
- --source-auth: 源redis密碼,如果有的話就填
- --source-database: 源database,默認(rèn)是 0
- --source-hosts: 源redis地址, 集群的多個(gè)ip用','隔開(kāi) (default "127.0.0.1:6379")
- --source-prefix: 源redis前綴, 可不填
- --source-redis-cluster: 源redis是否是集群, 默認(rèn) false
- --target-auth: 遷移目標(biāo)redis密碼,如果有的話就填
- --target-database: 遷移目標(biāo)database,默認(rèn)是 0
- --target-hosts: 遷移目標(biāo)redis地址, 集群的多個(gè)ip用','隔開(kāi) (default "127.0.0.1:6379")
- --target-prefix: 遷移目標(biāo)redis前綴, 可不填
- --target-redis-cluster: 遷移目標(biāo)redis是否是集群, 默認(rèn) false
遷移單個(gè)key的數(shù)據(jù)
下面就舉兩個(gè)例子吧,其他的都差不太多。
Hash類(lèi)型
可以通過(guò)命令 redis-tool migrate hash -h 查看使用說(shuō)明
$ 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

有序集合
可以通過(guò)命令 redis-tool migrate sorted-set -h 查看使用說(shuō)明
有序集合的數(shù)據(jù)量可能會(huì)比較大,所以這里按 50000 為單位進(jìn)行了切割。我這里測(cè)試過(guò)遷移近17000000萬(wàn)條的數(shù)據(jù),用時(shí)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ù)支持通配符過(guò)濾
可以通過(guò)命令 redis-tool migrate all -h 查看使用說(shuō)明
$ 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
這個(gè)命令會(huì)編譯匹配到的所有類(lèi)型的key,再根據(jù)key的類(lèi)型進(jìn)行逐步遷移。
尾巴
使用golang寫(xiě)的一個(gè)比較簡(jiǎn)單的工具, 主要用于在Redis沒(méi)有持久化或多套R(shí)edis向一套R(shí)edis遷移的情況下使用。
總結(jié)
到此這篇關(guān)于Redis migrate數(shù)據(jù)遷移工具的文章就介紹到這了,更多相關(guān)Redis migrate數(shù)據(jù)遷移工具內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文快速搞懂Redis的幾種數(shù)據(jù)類(lèi)型方式
這篇文章主要介紹了一文快速搞懂Redis的幾種數(shù)據(jù)類(lèi)型方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
Redis緩存和數(shù)據(jù)庫(kù)的數(shù)據(jù)一致性的問(wèn)題解決
隨業(yè)務(wù)增長(zhǎng),直接操作數(shù)據(jù)庫(kù)性能下降,引入緩存提高讀性能常見(jiàn),但緩存和數(shù)據(jù)庫(kù)的雙寫(xiě)操作會(huì)引發(fā)數(shù)據(jù)不一致問(wèn)題,本文討論幾種常用同步策略,感興趣的可以了解一下2024-09-09
Redis過(guò)期數(shù)據(jù)是否會(huì)被立馬刪除
這篇文章主要為大家介紹了Redis過(guò)期數(shù)據(jù)會(huì)被立馬刪除么的問(wèn)題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
redis中使用bloomfilter的白名單功能解決緩存穿透問(wèn)題
本文主要介紹了redis中使用bloomfilter的白名單功能解決緩存穿透問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
Redis的Zset類(lèi)型及相關(guān)命令詳細(xì)講解
這篇文章主要介紹了Redis的Zset類(lèi)型及相關(guān)命令的相關(guān)資料,有序集合Zset是一種Redis數(shù)據(jù)結(jié)構(gòu),它類(lèi)似于集合Set,但每個(gè)元素都有一個(gè)關(guān)聯(lián)的分?jǐn)?shù)score,并且可以根據(jù)分?jǐn)?shù)對(duì)元素進(jìn)行排序,需要的朋友可以參考下2025-01-01
springboot整合使用云服務(wù)器上的Redis方法
這篇文章主要介紹了springboot整合使用云服務(wù)器上的Redis,整合步驟通過(guò)導(dǎo)入依賴(lài),配置yml文件,注入redisTemplate結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),文中給大家分享了可能遇到的坑,感興趣的朋友跟隨小編一起看看吧2022-09-09
redis慢查詢(xún)?nèi)罩镜脑L問(wèn)和管理方式
這篇文章主要介紹了redis慢查詢(xún)?nèi)罩镜脑L問(wèn)和管理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12

