python - 如何使用 redis.py 运行哨兵命令
问题描述
是否可以像SENTINEL masters
使用 python 一样运行哨兵命令?链接在这里。
使用前sentinel.master_for("master_name")
需要知道master名,但是我使用的redis服务是公司私有云平台提供的,sentinel conf中的master名包含当前master节点的ip,如果master节点会被重写更改改变了,所以硬编码是不可能的。
目前,我的一个想法是子频道__sentinel__:hello
并从中解析主名称,但是,它看起来很不舒服。
有没有其他方法可以得到主人的名字?在终端中,我们可以使用 连接到哨兵redis-cli
并获取主信息SENTINEL masters
,这可以在 python 中完成吗?
解决方案
redis.py
本身可以用来连接到哨兵。
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
推荐阅读
- swift - 在 SwiftUI 中实现昂贵的派生属性的最佳方法是什么?
- flutter - 为什么有时上下文被替换为下划线或“_”?
- spring-boot - 使用外部承载令牌以执行 REST API
- sonarqube - 错误:org.h2.jdbc.JdbcSQLException:找不到表“USERS”
- java - 我可以将所有这些功能放入一个枚举中吗?
- python - python 显示错误:错误绑定参数 0 - 可能是不受支持的类型
- python - 使用 Apscheduler 时出错。Skipped:已运行的最大运行实例数(10)设置max_instances无效
- php - Wordpress 上的代码 PHP 不适用于 PHP 8
- sql - JOIN 子句的括号
- java - Android 应用程序在调试模式下完美运行,但在运行模式下冻结 Java