SharpRedis icon indicating copy to clipboard operation
SharpRedis copied to clipboard

连接阿里云 Tair 读写分离版本报错

Open MoondanceZ opened this issue 10 months ago • 3 comments

Image 这是 Redis 的相关配置, 我还有个常规版本, 是不会报错的

错误信息

SharpRedis.RedisConnectionException: Failed to connect to Redis, please check the network and Redis configuration. at SharpRedis.Network.Standard.BaseConnectionPool..ctor(ConnectionOptions masterConnectionOptions) at SharpRedis.Network.Pool.DefaultPool..ctor(ConnectionOptions masterConnectionOptions) at SharpRedis.Redis..ctor(ConnectionOptions connectionOptions) at SharpRedis.Redis.UseStandalone(String connectionString, Action`1 optionsAction)

MoondanceZ avatar Mar 11 '25 03:03 MoondanceZ

连接读写分离不能用UseStandalone哦, UseStandalone是单机节点连接用的. 读写分离用SharpRedis.Redis.UseMasterSlave方法

SharpRedis.Redis.UseMasterSlave("主节点连接字符串", new string[] { "从节点连接字符串1", "从节点连接字符串2" });
//或者这样
SharpRedis.Redis.UseMasterSlave(2/*2表示两个从节点*/, (master, slaves) =>
{
    master.Host = "127.0.0.1";      //设置主节点

    slaves[0].Host = "127.0.0.1";   //设置第一个从节点
    slaves[2].Host = "127.0.0.1";   //设置第二个从节点
});

q7164518 avatar Mar 14 '25 06:03 q7164518

阿里云这个是自动的呢,动态识别客户端的读写请求,然后请求自动转发到对应的主节点或只读节点上 不需要自己在链接的时候配置主从节点

MoondanceZ avatar Mar 14 '25 06:03 MoondanceZ

阿里云这个是自动的呢,动态识别客户端的读写请求,然后请求自动转发到对应的主节点或只读节点上 不需要自己在链接的时候配置主从节点

你说的这种是集群模式, 不是单纯的主从读写分离, 单纯的主从是我说的那样连接的. 集群模式暂时还没适配, 最近有点忙, 你可以先用其它的Redis驱动, 适配好了再告诉你, 你到时候再考虑用不用😂

q7164518 avatar Mar 14 '25 11:03 q7164518