redis-copy使用6379端口無(wú)法連接到Redis服務(wù)器的問(wèn)題
問(wèn)題描述
當(dāng)使用Azure Redis服務(wù)時(shí),需要把一個(gè)Redis服務(wù)的數(shù)據(jù)導(dǎo)入到另一個(gè)Redis上,因?yàn)镽edis服務(wù)沒(méi)有使用高級(jí)版,所以不支持直接導(dǎo)入/導(dǎo)出RDB文件。
以編程方式來(lái)讀取數(shù)據(jù)并寫(xiě)入到新的Redis服務(wù)端,使用開(kāi)源工具 Redis-Copy 卻遇見(jiàn)了 6379 端口無(wú)法連接的問(wèn)題。而用 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 工具呢?
問(wèn)題解答
根據(jù) redis-cli.exe 工具的驗(yàn)證,Redis服務(wù)器的 6379端口在同一個(gè)客戶端機(jī)器上,是可以正常連接的。那么問(wèn)題就需要轉(zhuǎn)移到 redis-copy.exe 的這個(gè)開(kāi)源工具上來(lái)研究了。
第一步:去 github 上下載 redis-copy的源碼:https://github.com/deepakverma/redis-copy
第二步:本地Visual Studio 工具打開(kāi)后,把啟動(dòng)指令后面攜帶的參數(shù)填入Debug Start options中
第三步:調(diào)試代碼,發(fā)現(xiàn)問(wèn)題根源是SSL的參數(shù)值依舊為T(mén)rue,而端口為 6379。 用SSL的方式去鏈接非SSL端口,這就是問(wèn)題的根源。
問(wèn)題出現(xiàn)在 CommandLine.Parser.Default.ParseArguments<Options>(args) 這句代碼上,經(jīng)過(guò)反復(fù)實(shí)現(xiàn),發(fā)現(xiàn)CommandLine在轉(zhuǎn)換 bool 類(lèi)型的時(shí)候,只要攜帶了這個(gè)參數(shù),不管內(nèi)容是什么,都會(huì)被轉(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賦值問(wèn)題
[主要]方案一:在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 的類(lèi)型為String,然后再初始化Redis連接字符串的時(shí)候轉(zhuǎn)換為bool類(lèi)型。
[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端口無(wú)法連接到Redis服務(wù)器的問(wèn)題的文章就介紹到這了,更多相關(guān)redis-copy無(wú)法連接到Redis服務(wù)器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Redis數(shù)據(jù)庫(kù)的應(yīng)用場(chǎng)景介紹
這篇文章主要介紹了Redis數(shù)據(jù)庫(kù)的應(yīng)用場(chǎng)景介紹,本文講解了MySql+Memcached架構(gòu)的問(wèn)題、Redis常用數(shù)據(jù)類(lèi)型、Redis數(shù)據(jù)類(lèi)型應(yīng)用和實(shí)現(xiàn)方式、Redis實(shí)際應(yīng)用場(chǎng)景等內(nèi)容,需要的朋友可以參考下2015-06-06淺談Redis位圖(Bitmap)及Redis二進(jìn)制中的問(wèn)題
這篇文章主要介紹了Redis位圖(Bitmap)及Redis二進(jìn)制中的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07redis調(diào)用二維碼時(shí)的不斷刷新排查分析
這篇文章主要為大家介紹了redis調(diào)用二維碼時(shí)不斷刷新排查分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2022-04-04redis 實(shí)現(xiàn)登陸次數(shù)限制的思路詳解
這篇文章主要介紹了redis 實(shí)現(xiàn)登陸次數(shù)限制的思路詳解,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08Redis哈希Hash鍵值對(duì)集合操作(查詢?cè)黾有薷?
Redis中的Hash數(shù)據(jù)?是一個(gè)?鍵值對(duì)集合,本文主要介紹了Redis哈希Hash鍵值對(duì)集合操作(查詢?cè)黾有薷?,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01Redis中主鍵失效的原理及實(shí)現(xiàn)機(jī)制剖析
這篇文章主要介紹了Redis中主鍵失效的原理及實(shí)現(xiàn)機(jī)制剖析,本文講解了失效時(shí)間的控制、失效的內(nèi)部實(shí)現(xiàn)、Memcached 刪除失效主鍵的方法與 Redis 有何異同、Redis 的主鍵失效機(jī)制會(huì)不會(huì)影響系統(tǒng)性能等內(nèi)容,需要的朋友可以參考下2015-06-06