gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 06:42:37 26 4
gpt4 key购买 nike

当我尝试按照此处的部署指南连接到主节点时遇到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com