from urllib.parse import quote
REDIS_PASSWORD = quote('123@456#789') # 将密码进行url编码
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f'mymaster/172.16.20.255:26379,172.16.21.253:26379,172.16.23.107:26379/1',
"OPTIONS": {
"CONNECTION_POOL_KWARGS": {"max_connections": 20,"decode_components": True}, # 需要配置decode_components为True,否则初始化redis连接池时还会有密码问题
"CLIENT_CLASS": "django_redis_sentinel.SentinelClient",
"PASSWORD": f"{REDIS_PASSWORD}",
}
}
}
- 对密码进行URL编码
- 在CONNECTION_POOL_KWARGS增加decode_components配置