如何处理“redis.exceptions.connectionerror:connection has data”

quhf5bfb  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(494)

我收到以下输出:

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()

这个错误是什么意思?

new9mtju

new9mtju1#

最后,我找到了问题的答案。当用python连接redis时,我用数字指定了数据库 0 .

redis = redis.Redis(host=example.com, port=6379, db=0)

把数据库改成数字后 1 成功了。

redis = redis.Redis(host=example.com, port=6379, db=1)

相关问题