飙血推荐
  • HTML教程
  • MySQL教程
  • JavaScript基础教程
  • php入门教程
  • JavaScript正则表达式运用
  • Excel函数教程
  • UEditor使用文档
  • AngularJS教程
  • ThinkPHP5.0教程

【Azure Redis 缓存】使用开源工具redis-copy时遇见6379端口无法连接到Redis服务器的问题

时间:2023-05-16  作者:lulight  

问题描述

当使用Azure Redis服务时,需要把一个Redis服务的数据导入到另一个Redis上,因为Redis服务没有使用高级版,所以不支持直接导入/导出RDB文件。

以编程方式来读取数据并写入到新的Redis服务端,使用开源工具 Redis-Copy 却遇见了 6379 端口无法连接的问题。而用 redis-域名 却正常连接。

redis-copy 工具使用 6379 端口

redis-域名

--se 域名域名 --sa <your source password> --sp 6379 --sssl false

--de 域名域名 --da <your destination password> --dp 6379 --dssl false

报错:

  • UnableToConnect on 域名域名:6379/Interactive 
  • No connection is available to service this operation 
  • It was not possible to connect to the redis server.

Redis-域名 工具使用 6379 端口,正常连接

redis-域名 -h 域名域名 -p 6379 -a YourAccessKey

那么,这是什么情况呢?如何才能正确使用 redis-域名 工具呢?

问题解答

根据 redis-域名 工具的验证,Redis服务器的 6379端口在同一个客户端机器上,是可以正常连接的。那么问题就需要转移到 redis-域名 的这个开源工具上来研究了。

第一步:去 github 上下载 redis-copy的源码:https://域名/deepakverma/redis-copy

第二步:本地Visual Studio 工具打开后,把启动指令后面携带的参数填入Debug Start options中

第三步:调试代码,发现问题根源是SSL的参数值依旧为True,而端口为 6379。 用SSL的方式去链接非SSL端口,这就是问题的根源。

问题出现在 域名域名eArguments<Options>(args) 这句代码上,经过反复实现,发现CommandLine在转换 bool 类型的时候,只要携带了这个参数,不管内容是什么,都会被转换为 true

第四步:解决办法

最快的解决办法 ---- 使用6380端口连接

redis-域名

 --se 域名域名 --sa <your source password> --sp 6380  

 --de 域名域名 --da <your destination password>  --dp 6380 

修改Redis-Copy源码 ---- 解决SSL赋值问题

[主要]方案一:在域名 文件中,修改 SourceSSL 和 DestinationSSL 的默认值为False。当需要使用6380端口连接时,携带 --sssl , --dssl参数

        [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-域名  --se xxxx --sa **** --sp 6379  --de xxxx --da **** --dp 6379  

使用6380端口的命令为: redis-域名  --se xxxx --sa **** --sp 6380 --sssl true  --de xxxx --da **** --dp 6380 --dssl true  

[其他]方案二:在域名 文件中,修改 SourceSSL 和 DestinationSSL 的类型为String,然后再初始化Redis连接字符串的时候转换为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();
            域名 =域名olean(域名ceSSL);
            域名word = 域名cePassword;
            域名wAdmin = true;
            域名Timeout = 60000; // increasing timeout for source for SCAN command
            sourcecon = GetConnectionMultiplexer(域名ceEndpoint, 域名cePort, configsource);

... ...

        ConfigurationOptions configdestination = new ConfigurationOptions();
            域名 = 域名olean(域名inationSSL);
            域名word = 域名inationPassword;
            域名wAdmin = true;
            destcon = GetConnectionMultiplexer(域名inationEndpoint, 域名inationPort, configdestination);

参考资料

以编程方式迁移 : https://域名/zh-cn/azure-cache-for-redis/cache-migration-guide#migrate-programmatically 

使用 Redis 命令行工具进行连接: https://域名/zh-cn/azure-cache-for-redis/cache-how-to-redis-cli-tool#connect-using-the-redis-command-line-tool

redis-copy : https://域名/deepakverma/redis-copy

标签:编程
湘ICP备14001474号-3  投诉建议:234161800@qq.com   部分内容来源于网络,如有侵权,请联系删除。