0

I have a code which connects to sentinels and discovers redis master address. After discovering master we create redis master object and perform redis operations afterwards. The problem here is that after sentinel failover process the redis master address gets changed and new master is promoted by the sentinels, in that case the redis master object should be updated at the run time. Can anyone tell how this can be achieved in real time?

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)

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

master_object = Redis(host, port)
master_object.get("data")
rhoitjadhav
  • 691
  • 7
  • 16
  • did you get any solution here – Vaibhav Mishra Aug 17 '22 at 11:20
  • One way to achieve this is by using try except block while performing redis operation. If there is ConnectionError exception occur then at that time we need to re-discover master and update the redis_master object. But I'm not satisfied with this solution though @VaibhavMishra – rhoitjadhav Aug 17 '22 at 13:14
  • Did you guys find a better solution than try-catch for this? – Dogukan Evcil Nov 18 '22 at 15:09

0 Answers0