redis-copy使用6379端口無法連接到Redis服務(wù)器的問題
問題描述
當(dāng)使用Azure Redis服務(wù)時,需要把一個Redis服務(wù)的數(shù)據(jù)導(dǎo)入到另一個Redis上,因為Redis服務(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
報錯:
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 工具的驗證,Redis服務(wù)器的 6379端口在同一個客戶端機器上,是可以正常連接的。那么問題就需要轉(zhuǎn)移到 redis-copy.exe 的這個開源工具上來研究了。
第一步:去 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ù)實現(xiàn),發(fā)現(xiàn)CommandLine在轉(zhuǎn)換 bool 類型的時候,只要攜帶了這個參數(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端口連接時,攜帶 --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連接字符串的時候轉(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 命令行工具進行連接: 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數(shù)據(jù)庫的應(yīng)用場景介紹
這篇文章主要介紹了Redis數(shù)據(jù)庫的應(yīng)用場景介紹,本文講解了MySql+Memcached架構(gòu)的問題、Redis常用數(shù)據(jù)類型、Redis數(shù)據(jù)類型應(yīng)用和實現(xiàn)方式、Redis實際應(yīng)用場景等內(nèi)容,需要的朋友可以參考下2015-06-06淺談Redis位圖(Bitmap)及Redis二進制中的問題
這篇文章主要介紹了Redis位圖(Bitmap)及Redis二進制中的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07redis 實現(xiàn)登陸次數(shù)限制的思路詳解
這篇文章主要介紹了redis 實現(xiàn)登陸次數(shù)限制的思路詳解,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08