1

Does it possible to run sentinel commands like SENTINEL masters with python? link is here.

Before using sentinel.master_for("master_name"), I have to know the master name, however, the redis service I used is provided by company's privite cloud platform, and the master name in sentinel conf contains the ip of current master node and would be rewrited and changed if the master node changed, so hard code it is not possible.

Currently, an idea for me is to sub the channel __sentinel__:hello and parse the master name from it, however, it looks so uncomfortable.

Is there another way to get master name? In terminal, we could connect to sentinel with redis-cli and get master info with SENTINEL masters, could this be done in python?

buxizhizhoum
  • 1,719
  • 1
  • 23
  • 32

1 Answers1

2

redis.py itself could be used to connect to sentinel.

import redis
sentinel_obj = redis.Redis(host="127.0.0.1", port=26379)  # pass the host and port of sentinel
sentinel_obj.sentinel_masters()  # this will get all available master-group-names in sentinel
buxizhizhoum
  • 1,719
  • 1
  • 23
  • 32