今天在python写入redis的时候碰到这个问题。下面是报错信息:
/home/ubuntu/.virtualenvs/zgxcw_incentive/local/lib/python2.7/site-packages/django_redis/__init__.pyc in get_redis_connection(alias, write)
16 """
17
---> 18 cache = get_cache(alias)
19 if not hasattr(cache.client, 'get_client'):
20 raise NotImplementedError("This backend does not supports this feature")
/home/ubuntu/.virtualenvs/zgxcw_incentive/local/lib/python2.7/site-packages/django/core/cache/__init__.pyc in get_cache(backend, **kwargs)
128 except (AttributeError, ImportError, ImproperlyConfigured) as e:
129 raise InvalidCacheBackendError(
--> 130 "Could not find backend '%s': %s" % (backend, e))
131 cache = backend_cls(location, params)
132 # Some caches -- python-memcached in particular -- need to do a cleanup at the
InvalidCacheBackendError: Could not find backend 'redis_cache.cache.RedisCache': Error importing module redis_cache.cache: "No module named redis_cache.cache"
解决方案:
查看了django-redis的版本
pip freeze | grep redis
django-redis==4.0.0
用的是4.0.0的版本,将django-redis的版本切到3.8.3,问题解决。
pip install django-redis==3.8.3
没有去细看这两个版本的区别在哪,有兴趣的同学可以查查。
也有人看到这个报错,说是环境变量的问题,有可能吧,各种可能都试试,说不好就解决了呢。