Ivan Studenikin
Ivan Studenikin

Reputation: 1463

Redis client. How to separate read/write operations?

We use StackExchange.Redis as redis client.

Is it possible to tell the client to use 127.0.0.1: 1001 strictly for Write and 127.0.0.2 strictly for Read?

enter image description here

Upvotes: 1

Views: 2619

Answers (1)

Oleg Alekseenko
Oleg Alekseenko

Reputation: 130

If your redis server 127.0.0.1:1002 is slaveof 127.0.0.1:1001, then you may execute your 'write' commands like that

redisClient.StringSet("key", "value", flags: CommandFlags.DemandMaster);

also, I can notice, that redisClient by it nature will execute commands needs 'write' on master. For 'read' commands you can write

redisClient.StringGet("key", flags: CommandFlags.DemandSlave);

But if your slave will be unavailable you will get an exception. Another option

CommandFlags.PreferSlave

from documentation:

This operation should be performed on the slave if it is available, but will be performed on a master if no slaves are available. Suitable for read operations only.

Upvotes: 1

Related Questions