4
votes

I am using redis server for my production environment and for HA I am using redis sentinel. But reading the documentation, when a client connects to the sentinel, sentinel gives client the master redis server.

Are all read and write operations are carried on the master server and the slave servers are only for failover or we can use the slave servers to read the data from?

1
which redis client is your application using.Tuco
Jredis. I am using it with spring data redis.Karan Khanna
I don't think Spring data redis supports it. Some java clients like Lettuce support it. Reading and writing from master is mostly ok as redis is blazingly fast. Also sometimes when there is slight fluctuation between master n slave, slave syncs itself with master, and slave can be very slow is responding to gets calls.Tuco

1 Answers

3
votes

But reading the documentation, when a client connects to the sentinel, sentinel gives client the master redis server.

Not quite, it will give you what you request from it. If you ask for the master, you get the master. If you ask for the slaves, it will return the list of slaves. You use sentinel master <name> to get the master, and sentinel slaves <name> for the list of slaves.

Thus if you want to do read-only operations on slaves, use a sentinel connection to get the slave list, then open a connection to one or more of those slaves. The tricky part will be that you will want your code to watch for and detect failovers so you know if your slave has been promoted and you can get the new slave list to use.

sidenote: don't think of it as "connecting to redis via sentinel". The would be as inaccurate as saying you "connect to a web server via DNS server" - sentinel is your lookup service, not a proxy connection.