2881099 / FreeRedis

🦄 FreeRedis is .NET40+ redis client. supports cluster, sentinel, master-slave, pub-sub, lua, pipeline, transaction, streams, client-side-caching, and pooling.
MIT License
924 stars 165 forks source link

docker compose搭建redis cluster使用FreeRedis填写的时宿主机ip:port连接时显示容器内ip,并提示连接超时不可用 #132

Open Sky-shang opened 1 year ago

Sky-shang commented 1 year ago

主机 FreeRedis Error

2881099 commented 1 year ago

无法连接,网络问题。

Sky-shang commented 1 year ago

不是网络问题,是FreeRedis用了我容器里面设定的主机ip173.18.0.3。并没有使用我写的宿主机127.0.0.1

2881099 commented 1 year ago

docker 配置内网节点应该使用127.0.0.1,而不应该用 173.xxx

Sky-shang commented 1 year ago

docker 配置内网节点应该使用127.0.0.1,而不应该用 173.xxx

redis_1: image: 'redis:7.0.8' container_name: redis_1 environment: TZ: 'Asia/Shanghai' healthcheck: test: ['CMD-SHELL', 'redis-cli --raw incr ping || exit 1'] interval: 5s timeout: 25s retries: 5 ports:

FreeRedis用的是我设置的容器内部地址173.18.03。而不是我连接字符串用的宿主机地址

2881099 commented 1 year ago

集群就是这样,或者你去命令行执行 cluster nodes 看到回结果。

2881099 commented 1 year ago

你启动 redis 用 0.0.0.0?

2881099 commented 7 months ago

针对这个问题:

public static RedisClient cli = new RedisClient(
    new ConnectionStringBuilder[] { "192.168.0.2:7001", "192.168.0.2:7002", "192.168.0.2:7003" },
    new Dictionary<string, string>
    {
        ["173.18.0.3:6379"] = ["192.168.1.1:6379"],
        ["173.18.0.4:6379"] = ["192.168.1.1:6380"]
    }
    );

需要结合 cluster nodes 返回的内容,确定 Dictionary 参数的 Key