Using StackExchange.Redis client with Redis cluster
Asked Answered
A

2

11

How do I tell StackExchange.Redis (v1.0.481) that it's about to connect to a Redis cluster (v3.2.6, in case it matters), and not just a standalone/replicated instance? When I use the redis-cli for example, I have to pass a -c flag to make it cluster-aware. Is there an equivalent flag in the StackExchange.Redis connection string?

I've searched for and come across several examples of connection strings that include multiple comma-separated host:port parameters, but nothing that explicitly makes StackExchange.Redis cluster-aware.

Thanks.

Ambiguity answered 14/12, 2016 at 10:54 Comment(0)
C
12

If you have a cluster, you will connect to the cluster no matter if you put one or more endpoints on the connection string. There is no flag to connect to a cluster.

Putting more than one endpoint on your connection string is good for High Availability, so if one of the nodes is down, you'll be able to start the connection to other node.

The internal list of nodes is updated and expanded automatically. You don't need to put all the endpoints on the connection string.

Check this issue for more details.

Comeon answered 19/12, 2016 at 5:25 Comment(5)
is your answer still accurate for client v1.2.6?Timeworn
but what if I have 3 master nodes with 3 slave nodes and each of them has different password? where can I pass these password?Teasley
@NiklausWirth AFAIK, you must use the same password in all the cluster servers. Check thisComeon
@Comeon as you said, it is good for HA to bring more endpoint to connectionString, and we dont need put all the endpoits. . first we should put all master and slaves address or just put Masters? for ex u have 3 master and 3 slave nodes which endpoint u put in ur connection string?Furman
@pejman I would suggest putting all master nodes in the cs, or use envoy as a proxy. Think of it this way... you have three(3) master nodes and each of them have a slave(replica). You have a master node failure, and your replica failsover the master node, now one of your master node ips has changed, but your cs has the other two, so you will still be able to discover the new master from them. Hope this helps your understanding of HA.Poseur
I
0

Like this:

_redisConnection = ConnectionMultiplexer.Connect(_clusterEndpoint);

var server = _redisConnection.GetServer(_clusterEndpoint);
_clustered = server.ServerType == ServerType.Cluster;
Inhere answered 15/11, 2023 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.