python - MasterNotFoundError 在连接到 Redis Sentinel 集群时使用 redis-py

标签 python redis bitnami redis-sentinel redis-py

当我尝试按照此处的部署指南连接到主节点时遇到 MasterNotFoundError:https://docs.bitnami.com/tutorials/deploy-redis-sentinel-production-cluster/

我连接到主 Redis Sentinel 节点的代码是:

from redis.sentinel import Sentinel

redis_host = 'redis.default.svc.cluster.local'
redis_port = 26379
sentinel = Sentinel([(redis_host, redis_port)], socket_timeout=0.1, password='abc')
redis_client = sentinel.master_for('mymaster', password='abc')

在他们的 GitHub repo ,我看到 sentinel.masterSet 的配置默认设置为 mymaster 。但是当我尝试使用下面的代码递增时:

redis_client.incr('counter', 1)

我遇到 redis.sentinel.MasterNotFoundError: No master found for 'mymaster' 错误。

我该如何解决这个问题?谢谢。

最佳答案

如此处报道https://github.com/andymccurdy/redis-py/issues/1125设置较低的 socket_timeout 会导致 MasterNotFound 错误,因为每个实例都被轮询但没有及时响应。您可以增加超时或将其删除以查看是否可以解决问题。

关于python - MasterNotFoundError 在连接到 Redis Sentinel 集群时使用 redis-py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60970856/

相关文章:

php - 如何在 EC2 实例上使用 PHP 设置和检索环境变量

python - 删除频率低的项目

python - python中令人毛骨悚然的设计

python - 使用 python 在生产中实现模型

python - 在没有 docker 的情况下将 tensorflow 模型部署到 GCP

concurrency - 使用 Celery 同时由两个工作进程运行的独特任务

azure - VMDepot 发生了什么?

amazon-web-services - AWS Bitnami 解析服务器 - 添加 HTTP 身份验证使我的应用程序在解析仪表板 'unauthorized'

caching - Redis中的 'node'到底是什么

redis - Redis:如何计算已排序列表时间序列中的时间差?