要订阅Sentinel故障转移,通道的名称是什么,以及如何检测我需要刷新订阅功能中的主控?如何在Sentinel和redis-py中使用Redis时故障切换到新主节点?
我有一个使用Redis Sentinel进行高可用性和故障转移的多节点Redis设置。
我需要将Pub/Sub设置为Redis来检测Redis Master何时失败并且系统选择了新的Master。
_sentinel = redis.sentinel.Sentinel([(app.config["REDIS_HOSTNAME"],app.config["REDIS_SENTINEL_PORT"])])
_master = _sentinel.master_for(app.config["REDIS_SERVICE_NAME"])
def _sentinel_message_handler(message):
#TODO how do I detect that there is a new Redis Master?
_pubsub = _master.pubsub()
_pubsub.subscribe(**{app.config["TODO"]:_sentinel_message_handler})
频道列表可以在这里找到:https://redis.io/topics/sentinel#pubsub-messages – davissp14
我在这里看到的一个问题是, REDIS_HOSTNAME应该通过一连串的Sentinel主机名连续尝试,直到连接完成。这样可以防止启动时因一个哨兵节点关闭而崩溃。 – 0111001101110000