AttributeError error connecting to redis cluster in Python 3.8

2.2k views Asked by At

I am attempting to connect to a redis cluster using the RedisCluster module in python 3.8.

redis-py-cluster==2.1.0

UPDATE: The connection works now after adding ssl=True.

However there is still an AttributeError being thrown which is a concern. Is this a possible bug with the rediscluster module?

  from rediscluster import RedisCluster

    _host = os.getenv('REDIS_HOST')
    _port = os.getenv('REDIS_PORT', 6379)
    _password = os.getenv('REDIS_PASSWORD')

    try:
      startup_nodes = [{"host": _host, "port": _port}]
      _redis_client = RedisCluster(startup_nodes=startup_nodes, decode_responses=True, ssl=True, password=_password)
    except Exception as x:
      print(x)

Error message:

{"event": "Starting gunicorn 20.0.4", "logger": "gunicorn.error", "level": "info", "timestamp": "2020-09-29T18:20:28.031445Z"}
{"event": "Listening at: http://0.0.0.0:8081 (1)", "logger": "gunicorn.error", "level": "info", "timestamp": "2020-09-29T18:20:28.032004Z"}
{"event": "Using worker: sync", "logger": "gunicorn.error", "level": "info", "timestamp": "2020-09-29T18:20:28.032130Z"}
{"event": "Booting worker with pid: 8", "logger": "gunicorn.error", "level": "info", "timestamp": "2020-09-29T18:20:28.035492Z"}
{"event": "Booting worker with pid: 9", "logger": "gunicorn.error", "level": "info", "timestamp": "2020-09-29T18:20:28.072118Z"}
{"event": "Booting worker with pid: 10", "logger": "gunicorn.error", "level": "info", "timestamp": "2020-09-29T18:20:28.172707Z"}
{"event": "Booting worker with pid: 11", "logger": "gunicorn.error", "level": "info", "timestamp": "2020-09-29T18:20:28.279041Z"}
{"event": "Created new instance of RedisCluster client instance", "logger": "rediscluster.client", "level": "info", "timestamp": "2020-09-29T18:20:59.366757Z"}
{"event": "Patching connection_class to SSLClusterConnection", "logger": "rediscluster.client", "level": "info", "timestamp": "2020-09-29T18:20:59.366940Z"}
{"event": "Using ClusterConnectionPool", "logger": "rediscluster.client", "level": "info", "timestamp": "2020-09-29T18:20:59.367051Z"}
{"event": "Creating new ClusterConnectionPool instance", "logger": "rediscluster.connection", "level": "info", "timestamp": "2020-09-29T18:20:59.367167Z"}
Exception ignored in: <function Redis.__del__ at 0x7fbc965cd820>
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/redis/client.py", line 885, in __del__
    self.close()
  File "/usr/local/lib/python3.8/site-packages/redis/client.py", line 888, in close
    conn = self.connection
AttributeError: 'RedisCluster' object has no attribute 'connection'
{"event": "10.255.0.2 - - [29/Sep/2020:18:20:59 +0000] \"GET /lookup/URN-3:IIIF_DEMO:10001 HTTP/1.1\" 200 3 \"-\" \"PostmanRuntime/7.26.5\"", "logger": "gunicorn.access", "level": "info", "timestamp": "2020-09-29T18:20:59.515711Z"}
0

There are 0 answers