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?
CodePudding user response:
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 redisGetServer(...)
exposes the underlying infrastructure of redis servers that provide that database