1

If you have multiple connections in

ConnectionMultiplexer.Connect(host1, host2, etc.)

and

StackExchange.ConnectionMultiplexer.GetServer(...)

requires exactly 1 endpoint to get server - how to understand this ? How does this makes sense?

1 Answer 1

2

However you connect, behind the scenes the multiplexer may have knowledge of multiple redis server instances. Usually, the server topology is an implementation detail that isn't useful or necessary to the consumer - which is why it isn't needed for APIs exposed under GetDatabase(); the library will worry about how to route commands to servers.

However, sometimes, a consumer wants to use an API that is specific to an individual server endpoint; this is where GetServer() comes into play. This could be, for example, to read (or change) individual server configurations (although other APIs exist). In that scenario, you obviously need to tell the library which node you want to talk to, which is why this is a required parameter to GetServer(). Note that you can use the GetEndPoints() API to list the endpoints in play (this is not necessarily the same as the endpoints you supplied in Connect[Async] - for example, a redis cluster declares the topology via a redis command, usually additional nodes).

If you aren't sure what endpoint you would pass to GetServer(...), then there's a good chance that you shouldn't be using GetServer(...) - by which I mean: the functionality you're after is probably exposed on GetDatabase(...) instead - which does not require an endpoint to be specified.

Or perhaps more simply:

  • GetDatabase(...) exposes the logical database constructed within redis
  • GetServer(...) exposes the underlying infrastructure of redis servers that provide that database
Sign up to request clarification or add additional context in comments.

5 Comments

Thx for explanation. I checked my code and the only time where I need GetServer(...), is to make a query about the keys: IServer.Keys(...) There is no other way (GetDatabase(...)) to query keys right?
@sabiland yes; despite what it is tempting to think, keys is a server-centric API: stackexchange.github.io/StackExchange.Redis/KeysScan.html
Ok thanks for clearing this up! Just another quick question, can I put sentinel host/port to GetServer(...) ?
@sabiland are you actually talking to a sentinel instance as sentinel (not as a gateway to redis) at the time? if so.... maybe, I haven't tried; if not: no
We are setting up Sentinels on staging today. Will try all variants with GetServer(...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.