在django-redis中使用哨兵时无法连接到redis



目前我正试图将redis集成到我的django项目中,这是基于docker的。我能够使用DefaultClient集成redis,但它不适用于SentinelClient

我的settings.py看起来像这样:

DJANGO_REDIS_CONNECTION_FACTORY = 'django_redis.pool.SentinelConnectionFactory'

SENTINELS = [
('redis://redis-sentinel', 26379),
]
# redis-sentinel is the name of redis sentinel container
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://redis-queue-1:6379',
'OPTIONS': {
'SENTINELS': SENTINELS,
# django_redis.client.SentinelClient
'CLIENT_CLASS': 'django_redis.client.SentinelClient',
'CONNECTION_POOL_CLASS': 'redis.sentinel.SentinelConnectionPool',
},
}
}

不会抛出任何异常,django只是在加载

时卡住了编辑:

在尝试打开shell并手动设置缓存密钥时我看到这个错误

redis.sentinel.MasterNotFoundError: No master found for 'redis-queue-1'

虽然我使用了相同的服务名称默认客户端,它的工作,但提出了一个错误的SentinelClient

尝试使用https://pypi.org/project/django-sentinel/

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis_master/sentinel-host1:2639,sentinel-host2:2639/0"
"OPTIONS": {
"PASSWORD": 's3cret_passw0rd!',
"CLIENT_CLASS": "django_sentinel.SentinelClient",
}
}
}

最新更新