我正在使用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
追踪(最近一次通话): redis.exceptions.ConnectionError:错误-2连接到127.0.0.1:20789:0。名称或服务未知。
请注意,在这两种情况下,主机,端口和数据库都是相同的。
使用import redis
已经是一个调试;使用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,
}
}
答案 0 :(得分:2)
我猜,但你有:
'LOCATION': '127.0.0.1:20789:0'
而django-redis-cache的自述文件指定:
'LOCATION': '<host>:<port>'
即。最后没有:<db>