#go-redis cluster client

5 messages · Page 1 of 1 (latest)

hearty agate
#

I'm trying to use the go-redis cluster client (https://github.com/redis/go-redis) to connect from a locally running application to a locally running redis cluster within a locally running k8s cluster (k3d to run the k8s cluster, using the bitnami redis-cluster helm chart to stand up the redis cluster). I am port-forwarding the redis cluster ports using kubectl to local ports (10000, 10001, 10002), which should allow me to do the following:

client := redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{":10000", ":10001", ":10002"},
})

I'm running into the issue that the cluster client logic begins with using first provided address (localhost:10000), and from there starts trying to use the k8s cluster IPs instead: "dial tcp 10.42.1.18:6379: i/o timeout"

Why does it not just use the addresses I have provided? Is there something I am doing wrong?

GitHub

Redis Go client. Contribute to redis/go-redis development by creating an account on GitHub.

patent nexus
#

Hi @hearty agate , the way how the cluster API works is that the client sends a CLUSTER SLOTS command to any of the provided endpoint. This command returns the actual IP-s of the nodes when bootstrapping the client.

#

So what you are seeing is the expected behaviour when using a cluster client. The application that uses the client needs to be able to reach the cluster nodes on their configured IP-s.

hearty agate
#

Hi @patent nexus, thanks for the reply! So that sounds like with the current behaviour I will be unable to use a Redis cluster client with a port-forwarded Redis cluster. Or is there some way to configure what IPs are returned from the CLUSTER SLOTS command?

patent nexus
#

Some client libraries allow you to map the result that you get from CLUSTER SLOTS in a customized way to simplify local testing if using a containerized environment. The best I found in the go-redis client was https://github.com/redis/go-redis/blob/master/osscluster.go#L57C53-L57C58 . So you might provide a ClusterSlots function as part of the ClusterOptions that returns the published ports instead of the internal endpoints. You should only use this during development. In production, your application should be able reach the actual IP addresses of the Redis nodes.

GitHub

Redis Go client. Contribute to redis/go-redis development by creating an account on GitHub.