只需要安装一下python redis库即可。
pip install redis
根据报错位置来到kombu代码中,kombu是一个python中的消息中间件,使用celery会依赖到这个库,代码是这个样子:
class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
"""Returns a ``StrictRedis`` client that prefixes the keys it uses."""
def __init__(self, *args, **kwargs):
self.global_keyprefix = kwargs.pop('global_keyprefix', '')
redis.Redis.__init__(self, *args, **kwargs)
报错为:
File "d:\xxxx\venv\lib\site-packages\kombu\transport\redis.py", line 263, in <module>
class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
AttributeError: 'NoneType' object has no attribute 'Redis'
明显参数位置的redis是None,再看redis定义的地方:
try:
import redis
except ImportError: # pragma: no cover
redis = None
这样写的话当导入redis失败时会捕获ImportError,而不会报出来,从而导致了后面的错误,所以我们看不到导入redis失败的信息。而认为是其他错误。
正向来想一下,我们使用redis作为broker,需要导入redis库来连接数据库也是很合理的。