2

我正在尝试在启用 TLS 的情况下连接 AWS elasticache(集群模式下的 redis),库版本和 django 缓存设置如下

====Dependencies======
redis==3.0.0
redis-py-cluster==2.0.0
django-redis==4.11.0

======settings=======
CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': "redis://xxxxxxx.mc-redis-cache-v2.zzzzz.usw2.cache.amazonaws.com:6379/0",
        'OPTIONS': {
            'PASSWORD': '<password>',
            'REDIS_CLIENT_CLASS': 'rediscluster.RedisCluster',
            'CONNECTION_POOL_CLASS': 'rediscluster.connection.ClusterConnectionPool',
            'CONNECTION_POOL_KWARGS': {
                'skip_full_coverage_check': True,
                "ssl_cert_reqs": False,
                "ssl": True
            }
        }
    }
}

客户端类(由redis-py-cluster提供)似乎没有问题,因为我可以访问

from rediscluster import RedisCluster
startup_nodes = [{"host": "redis://xxxxxxx.mc-redis-cache-v2.zzzzz.usw2.cache.amazonaws.com", "port": "6379"}]

rc = RedisCluster(startup_nodes=startup_nodes, ssl=True, ssl_cert_reqs=False, decode_responses=True, skip_full_coverage_check=True, password='<password>')

rc.set("foo", "bar")
rc.get('foo')
'bar'

但是当 django 服务尝试访问缓存时,我看到了这个错误,是否有任何我可能遗漏的配置细节?

File "/usr/lib/python3.6/site-packages/django_redis/cache.py", line 32, in _decorator
    return method(self, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/django_redis/cache.py", line 81, in get
    client=client)
  File "/usr/lib/python3.6/site-packages/django_redis/client/default.py", line 194, in get
    client = self.get_client(write=False)
  File "/usr/lib/python3.6/site-packages/django_redis/client/default.py", line 90, in get_client
    self._clients[index] = self.connect(index)
  File "/usr/lib/python3.6/site-packages/django_redis/client/default.py", line 103, in connect
    return self.connection_factory.connect(self._server[index])
  File "/usr/lib/python3.6/site-packages/django_redis/pool.py", line 64, in connect
    connection = self.get_connection(params)
  File "/usr/lib/python3.6/site-packages/django_redis/pool.py", line 75, in get_connection
    pool = self.get_or_create_connection_pool(params)
  File "/usr/lib/python3.6/site-packages/django_redis/pool.py", line 94, in get_or_create_connection_pool
    self._pools[key] = self.get_connection_pool(params)
  File "/usr/lib/python3.6/site-packages/django_redis/pool.py", line 107, in get_connection_pool
    pool = self.pool_cls.from_url(**cp_params)
  File "/usr/lib/python3.6/site-packages/redis/connection.py", line 916, in from_url
    return cls(**kwargs)
  File "/usr/lib/python3.6/site-packages/rediscluster/connection.py", line 146, in __init__
    self.nodes.initialize()
  File "/usr/lib/python3.6/site-packages/rediscluster/nodemanager.py", line 172, in initialize
    raise RedisClusterException("ERROR sending 'cluster slots' command to redis server: {0}".format(node))
rediscluster.exceptions.RedisClusterException: ERROR sending 'cluster slots' command to redis server: {'host': 'xxxxxxx.mc-redis-cache-v2.zzzzz.usw2.cache.amazonaws.com', 'port': '6379'}

我还尝试传递"ssl_ca_certs": "/etc/ssl/certs/ca-certificates.crt"并将CONNECTION_POOL_KWARGS位置方案设置为rediss仍然没有运气

4

1 回答 1

2

您需要将 ssl_cert_reqs=False 更改为 ssl_cert_reqs=None

这是指向此的 redis Python git repo 的链接: https ://github.com/andymccurdy/redis-py#ssl-connections

于 2020-07-13T19:55:11.330 回答