Django中的Redis:redis.exceptions.ConnectionError:错误-2连接到127.0.0.1:20789:0。名称或服务未知

时间:2015-01-14 20:18:28

标签: python django redis

我正在使用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 question127.0.0.1更改为localhost,但没有成功。

知道这可能是什么?

我的CACHES配置已经是最小配置了:

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.cache.RedisCache',
        'LOCATION': '127.0.0.1:20789:0',
        'TIMEOUT': 60*60*24,
    }
}

1 个答案:

答案 0 :(得分:2)

我猜,但你有:

'LOCATION': '127.0.0.1:20789:0'

而django-redis-cache的自述文件指定:

'LOCATION': '<host>:<port>'

即。最后没有:<db>

https://github.com/sebleier/django-redis-cache