简体   繁体   中英

How to SET on specific redis server with StackExchange.Redis client?

I have 3 redis servers running in docker containers. From redis-cli I can SET on specific server.

SET myValue 100

How can I do this with StackExchange.Redis client?

I don't see anything in server api that allows to do that. Bear in mind that I don't know much about Redis at all.

var connection = ConnectionMultiplexer.Connect("localhost:6379,localhost:6380,localhost:6381");
var server = connection.GetServer("localhost", 6381);
server.???

SE.Redis expects to be managing a single logical keyspace; the support for multiple nodes is intended either for master/replica setups, or for redis-cluster (although, in the case of cluster, node discovery is achieved via the redis API, so a single node would be fine if it is reachable). With that in place: the selection of servers is implicit from the operation (ie writes need to go to a master, and in the case of "cluster", the keyspace shard mapping should be applied).

If you want to write to separate servers as though they are separate databases , you should use a connection per server; not a single connection that spans them all. Right now, SE.Redis is probably detecting 3 master nodes and electing to use one of them arbitrarily. You can see what it thinks by passing a TextWriter to the Connect / ConnectAsync method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM