redis-copy使用6379端口無法連接到Redis服務(wù)器的問題
問題描述
當(dāng)使用Azure Redis服務(wù)時(shí),需要把一個(gè)Redis服務(wù)的數(shù)據(jù)導(dǎo)入到另一個(gè)Redis上,因?yàn)镽edis服務(wù)沒有使用高級版,所以不支持直接導(dǎo)入/導(dǎo)出RDB文件。
以編程方式來讀取數(shù)據(jù)并寫入到新的Redis服務(wù)端,使用開源工具 Redis-Copy 卻遇見了 6379 端口無法連接的問題。而用 redis-cli.exe 卻正常連接。
redis-copy 工具使用 6379 端口
redis-copy.exe --se xxxxx.redis.cache.chinacloudapi.cn --sa <your source password> --sp 6379 --sssl false --de xxxxx.redis.cache.chinacloudapi.cn --da <your destination password> --dp 6379 --dssl false
報(bào)錯(cuò):
UnableToConnect on xxxxxxxx.redis.cache.chinacloudapi.cn:6379/Interactive No connection is available to service this operation It was not possible to connect to the redis server.


Redis-cli.exe 工具使用 6379 端口,正常連接
redis-cli.exe -h yourcachename.redis.cache.chinacloudapi.cn -p 6379 -a YourAccessKey

那么,這是什么情況呢?如何才能正確使用 redis-copy.exe 工具呢?
問題解答
根據(jù) redis-cli.exe 工具的驗(yàn)證,Redis服務(wù)器的 6379端口在同一個(gè)客戶端機(jī)器上,是可以正常連接的。那么問題就需要轉(zhuǎn)移到 redis-copy.exe 的這個(gè)開源工具上來研究了。
第一步:去 github 上下載 redis-copy的源碼:https://github.com/deepakverma/redis-copy
第二步:本地Visual Studio 工具打開后,把啟動指令后面攜帶的參數(shù)填入Debug Start options中

第三步:調(diào)試代碼,發(fā)現(xiàn)問題根源是SSL的參數(shù)值依舊為True,而端口為 6379。 用SSL的方式去鏈接非SSL端口,這就是問題的根源。

問題出現(xiàn)在 CommandLine.Parser.Default.ParseArguments<Options>(args) 這句代碼上,經(jīng)過反復(fù)實(shí)現(xiàn),發(fā)現(xiàn)CommandLine在轉(zhuǎn)換 bool 類型的時(shí)候,只要攜帶了這個(gè)參數(shù),不管內(nèi)容是什么,都會被轉(zhuǎn)換為 true
第四步:解決辦法
最快的解決辦法 ---- 使用6380端口連接
redis-copy.exe --se xxxxx.redis.cache.chinacloudapi.cn --sa <your source password> --sp 6380 --de xxxxx.redis.cache.chinacloudapi.cn --da <your destination password> --dp 6380
修改Redis-Copy源碼 ---- 解決SSL賦值問題
[主要]方案一:在Options.cs 文件中,修改 SourceSSL 和 DestinationSSL 的默認(rèn)值為False。當(dāng)需要使用6380端口連接時(shí),攜帶 --sssl , --dssl參數(shù)
[Option("sssl", Required = false, Default = false, HelpText = "Connect Source over ssl" )]
public bool SourceSSL { get; set; }
... ...
[Option("dssl", Required = false, Default = false, HelpText = "Destination Source over ssl" )]
public bool DestinationSSL { get; set; }修改代碼,重新編譯exe文件后。
使用6379端口的命令為: redis-copy.exe --se xxxx --sa **** --sp 6379 --de xxxx --da **** --dp 6379
使用6380端口的命令為: redis-copy.exe --se xxxx --sa **** --sp 6380 --sssl true --de xxxx --da **** --dp 6380 --dssl true
[其他]方案二:在Options.cs 文件中,修改 SourceSSL 和 DestinationSSL 的類型為String,然后再初始化Redis連接字符串的時(shí)候轉(zhuǎn)換為bool類型。
[Option("sssl", Required = false, Default = true, HelpText = "Connect Source over ssl" )]
public string SourceSSL { get; set; }
... ...
[Option("dssl", Required = false, Default = true, HelpText = "Destination Source over ssl" )]
public string DestinationSSL { get; set; }
.... ....
ConfigurationOptions configsource = new ConfigurationOptions();
configsource.Ssl =Convert.ToBoolean(options.SourceSSL);
configsource.Password = options.SourcePassword;
configsource.AllowAdmin = true;
configsource.SyncTimeout = 60000; // increasing timeout for source for SCAN command
sourcecon = GetConnectionMultiplexer(options.SourceEndpoint, options.SourcePort, configsource);
... ...
ConfigurationOptions configdestination = new ConfigurationOptions();
configdestination.Ssl = Convert.ToBoolean(options.DestinationSSL);
configdestination.Password = options.DestinationPassword;
configdestination.AllowAdmin = true;
destcon = GetConnectionMultiplexer(options.DestinationEndpoint, options.DestinationPort, configdestination);參考資料
以編程方式遷移 : https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-migration-guide#migrate-programmatically
使用 Redis 命令行工具進(jìn)行連接: https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-how-to-redis-cli-tool
redis-copy : https://github.com/deepakverma/redis-copy
到此這篇關(guān)于redis-copy使用6379端口無法連接到Redis服務(wù)器的問題的文章就介紹到這了,更多相關(guān)redis-copy無法連接到Redis服務(wù)器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Redis GEO實(shí)現(xiàn)搜索附近用戶的項(xiàng)目實(shí)踐
RedisGEO主要用于存儲地理位置信息,并對存儲的信息進(jìn)行操作,本文主要介紹了Redis GEO實(shí)現(xiàn)搜索附近用戶的項(xiàng)目實(shí)踐,具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05
CentOS系統(tǒng)下Redis安裝和自啟動配置的步驟
相信大家都知道Redis是一個(gè)C實(shí)現(xiàn)的基于內(nèi)存、可持久化的鍵值對數(shù)據(jù)庫,在分布式服務(wù)中常作為緩存服務(wù)。所以這篇文章將詳細(xì)介紹在CentOS系統(tǒng)下如何從零開始安裝到配置啟動服務(wù)。有需要的可以參考借鑒。2016-09-09
微服務(wù)Spring Boot 整合 Redis 實(shí)現(xiàn)好友關(guān)注功能
這篇文章主要介紹了微服務(wù)Spring Boot 整合 Redis 實(shí)現(xiàn) 好友關(guān)注,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-12-12
使用百度地圖api通過redis實(shí)現(xiàn)地標(biāo)存儲及范圍坐標(biāo)點(diǎn)查詢功能
這篇文章主要介紹了使用百度地圖api通過redis實(shí)現(xiàn)地標(biāo)存儲及范圍坐標(biāo)點(diǎn)查詢功能,本文通過圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2021-08-08
分布式利器redis及redisson的延遲隊(duì)列實(shí)踐
這篇文章為大家主要介紹了分布式利器redis及redisson的延遲隊(duì)列實(shí)踐,搜遍全網(wǎng)好像還沒有使用redisson的延遲隊(duì)列的,redisson作為一個(gè)分布式利器,這么好用的工具沒人用有點(diǎn)可惜2022-03-03
Redis中Redisson布隆過濾器的學(xué)習(xí)
布隆過濾器是一個(gè)非常長的二進(jìn)制向量和一系列隨機(jī)哈希函數(shù)的組合,可用于檢索一個(gè)元素是否存在,本文就詳細(xì)的介紹一下Redisson布隆過濾器,具有一定的參考價(jià)值,感興趣的可以了解一下2022-05-05
Redis數(shù)據(jù)結(jié)構(gòu)之鏈表詳解
大家好,本篇文章主要講的是Redis數(shù)據(jù)結(jié)構(gòu)之鏈表詳解,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12

