user7295971
user7295971

Reputation: 111

Using StackExchange.Redis client with Redis cluster

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.

Upvotes: 11

Views: 16437

Answers (2)

xagyg
xagyg

Reputation: 9711

Like this:

_redisConnection = ConnectionMultiplexer.Connect(_clusterEndpoint);

var server = _redisConnection.GetServer(_clusterEndpoint);
_clustered = server.ServerType == ServerType.Cluster;

Upvotes: 0

thepirat000
thepirat000

Reputation: 13114

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.

Upvotes: 12

Related Questions