如何处理“Redis.exceptions.ConnectionError:连接有数据”
Posted
技术标签:
【中文标题】如何处理“Redis.exceptions.ConnectionError:连接有数据”【英文标题】:How to handle "Redis.exceptions.ConnectionError: Connection has data" 【发布时间】:2020-07-18 14:41:41 【问题描述】:我收到以下输出:
Traceback (most recent call last):
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/connection.py", line 1192, in get_connection
raise ConnectionError('Connection has data')
redis.exceptions.ConnectionError: Connection has data
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/hubs/hub.py", line 457, in fire_timers
timer()
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/hubs/timer.py", line 58, in __call__
cb(*args, **kw)
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/greenthread.py", line 214, in main
result = function(*args, **kwargs)
File "crawler.py", line 53, in fetch_listing
url = dequeue_url()
File "/home/ec2-user/WebCrawler/helpers.py", line 109, in dequeue_url
return redis.spop("listing_url_queue")
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/client.py", line 2255, in spop
return self.execute_command('SPOP', name, *args)
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/client.py", line 875, in execute_command
conn = self.connection or pool.get_connection(command_name, **options)
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/connection.py", line 1197, in get_connection
raise ConnectionError('Connection not ready')
redis.exceptions.ConnectionError: Connection not ready
我找不到与此特定错误相关的任何问题。我清空/刷新了所有 redis 数据库,所以那里应该没有数据。我认为它与eventlet
和修补有关。但即使我将以下代码放在文件的开头,也会出现错误。
import eventlet
eventlet.monkey_path()
这个错误是什么意思?
【问题讨论】:
【参考方案1】:另一种方法是在etc\redis\redis.conf
中将protected_mode
设置为no。建议在本地运行 redis 时使用。
【讨论】:
【参考方案2】:最后,我想出了我的问题的答案。
用python连接redis时,我指定了编号为0
的数据库。
redis = redis.Redis(host=example.com, port=6379, db=0)
将数据库更改为数字1
后,它起作用了。
redis = redis.Redis(host=example.com, port=6379, db=1)
【讨论】:
以上是关于如何处理“Redis.exceptions.ConnectionError:连接有数据”的主要内容,如果未能解决你的问题,请参考以下文章