我正在使用 django-cache-redis,但我陷入了以下悖论:
# in `python manage.py shell`
import redis
r = redis.StrictRedis(host='127.0.0.1', port=20789, db=0)
r.set('foo', 'bar') # returns True
from django.core.cache import cache
cache.set('foo', 'bar', 1) # raises redis.exceptions.ConnectionError
Traceback (most recent call last): redis.exceptions.ConnectionError: Error -2 connecting to 127.0.0.1:20789:0. Name or service not known.
请注意主机、端口和数据库在这两种情况下都是相同的。
使用import redis
已经是debug;使用 redis-ctl 也可以。我还尝试根据 this question 将 127.0.0.1
更改为 localhost
, 没有成功。
知道这可能是什么吗?
我的 CACHES
配置已经是最小的了:
CACHES = {
'default': {
'BACKEND': 'redis_cache.cache.RedisCache',
'LOCATION': '127.0.0.1:20789:0',
'TIMEOUT': 60*60*24,
}
}
最佳答案
我猜,但你有:
'LOCATION': '127.0.0.1:20789:0'
而 django-redis-cache 的自述文件指定:
'LOCATION': '<host>:<port>'
即没有 :<db>
最后
关于python - Django 中的 Redis : redis. exceptions.ConnectionError : Error -2 connecting to 127. 0.0.1 :20789:0. 名称或服务未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27951678/