【问题标题】:Redis in Django: redis.exceptions.ConnectionError: Error -2 connecting to 127.0.0.1:20789:0. Name or service not knownDjango 中的 Redis:redis.exceptions.ConnectionError:连接到 127.0.0.1:20789:0 时出现错误 -2。名称或服务未知
【发布时间】:2015-01-14 20:18:27
【问题描述】:

我正在使用 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(最近一次调用最后一次): redis.exceptions.ConnectionError:连接到 127.0.0.1:20789:0 时出现错误 -2。名称或服务未知。

注意host、port和db在这两种情况下都是一样的。

import redis的使用已经是debug了;使用 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,
    }
}

【问题讨论】:

    标签: python django redis


    【解决方案1】:

    我猜,但你有:

    'LOCATION': '127.0.0.1:20789:0'
    

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

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

    即最后没有:&lt;db&gt;

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

    【讨论】:

    • 废话。我错误地从 Django-Celery 中获取了符号:BROKER_URL = 'redis://127.0.0.1:20789/0'。谢谢!
    猜你喜欢
    • 2014-09-30
    • 1970-01-01
    • 2018-12-18
    • 2023-03-29
    • 1970-01-01
    • 2013-07-24
    • 2015-06-12
    • 2013-12-14
    • 2018-01-05
    相关资源
    最近更新 更多