连接到Python 3.8中的Redis集群的AttributeError错误

问题描述

我正在尝试使用python 3.8中的RedisCluster模块连接到Redis集群。

redis-py-cluster==2.1.0

更新:添加ssl = True后,连接现在可以正常工作。

但是仍然存在引发AttributeError的问题。 rediscluster模块可能是这个错误吗?

  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)

错误消息:

{"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)","timestamp": "2020-09-29T18:20:28.032004Z"}
{"event": "Using worker: sync","timestamp": "2020-09-29T18:20:28.032130Z"}
{"event": "Booting worker with pid: 8","timestamp": "2020-09-29T18:20:28.035492Z"}
{"event": "Booting worker with pid: 9","timestamp": "2020-09-29T18:20:28.072118Z"}
{"event": "Booting worker with pid: 10","timestamp": "2020-09-29T18:20:28.172707Z"}
{"event": "Booting worker with pid: 11","timestamp": "2020-09-29T18:20:28.279041Z"}
{"event": "Created new instance of RedisCluster client instance","logger": "rediscluster.client","timestamp": "2020-09-29T18:20:59.366757Z"}
{"event": "Patching connection_class to SSLClusterConnection","timestamp": "2020-09-29T18:20:59.366940Z"}
{"event": "Using ClusterConnectionPool","timestamp": "2020-09-29T18:20:59.367051Z"}
{"event": "Creating new ClusterConnectionPool instance","logger": "rediscluster.connection","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","timestamp": "2020-09-29T18:20:59.515711Z"}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)