1

I'm trying to connect to redis using sentinel by discovering master and then creating instance of discovered master. The following snippet implements the same. As per my understanding, first it is discovering master which takes 1 network call and then to perform any operation on redis its also taking 1 more network call i.e. total 2 network calls. So whenever I want to do any operation on redis I have to first discover the master and then by creating the instance of redis master I can perform certain operations. My question is, is there any way to reduce the extra network call?

Feel free to share your thoughts if I misunderstood something or have any suggestions regarding the approach.

from redis import Redis
from redis.sentinel import Sentinel

sentinel = Sentinel([('192.168.10.1', 26379), ('192.168.10.2', 26379),
                     ('192.168.10.3', 26379)], socket_timeout=0.1)

host, port = sentinel.discover_master("master-name")

r = Redis(host, port)
r.get("data")
rhoitjadhav
  • 691
  • 7
  • 16

0 Answers0