如何使用 redis.py 运行 哨兵命令
How to run sentinel commands with redis.py
是否可以 运行 像 SENTINEL masters
和 python 这样的哨兵命令? link 是 here。
在使用sentinel.master_for("master_name")
之前,我需要知道master名称,但是我使用的redis服务是公司私有云平台提供的,sentinel conf中的master名称包含当前master节点的ip如果主节点发生变化,将被重写和更改,因此不可能进行硬编码。
目前,我的想法是将频道 __sentinel__:hello
子频道并从中解析主名称,但是,它看起来很不舒服。
还有其他方法可以获取主人名字吗?在终端中,我们可以使用 redis-cli
连接到 sentinel 并使用 SENTINEL masters
获取 master 信息,这可以在 python 中完成吗?
redis.py
本身可用于连接到 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
是否可以 运行 像 SENTINEL masters
和 python 这样的哨兵命令? link 是 here。
在使用sentinel.master_for("master_name")
之前,我需要知道master名称,但是我使用的redis服务是公司私有云平台提供的,sentinel conf中的master名称包含当前master节点的ip如果主节点发生变化,将被重写和更改,因此不可能进行硬编码。
目前,我的想法是将频道 __sentinel__:hello
子频道并从中解析主名称,但是,它看起来很不舒服。
还有其他方法可以获取主人名字吗?在终端中,我们可以使用 redis-cli
连接到 sentinel 并使用 SENTINEL masters
获取 master 信息,这可以在 python 中完成吗?
redis.py
本身可用于连接到 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