Django-redis配置使用套接字而不是TCP

时间:2013-07-09 15:24:27

标签: django redis django-redis

我正在尝试使用django-redis using Unix sockets rather than a TCP connection

这是settings.py配置:

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.cache.RedisCache',
        'LOCATION': 'unix:/tmp/redis.sock:1',
        'OPTIONS': {
            'PASSWORD': '',
            'PICKLE_VERSION': -1,   # default
            'PARSER_CLASS': 'redis.connection.HiredisParser',
            'CLIENT_CLASS': 'redis_cache.client.DefaultClient',
        },
    },
}

这是/etc/redis/6379.conf的redis配置文件的摘录:

# Specify the path for the unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
unixsocket /tmp/redis.sock
unixsocketperm 755

我仍然收到ConnectionInterrumped异常,代表连接期间的错误。关于这个配置的问题是什么想法?

P.S。我的Django版本为1.5.1,django-redis为3.3,hiredis为0.0.1

1 个答案:

答案 0 :(得分:2)

编辑:显然我读错了缓存提供程序,下面的答案是django-redis-cache的解决方案,而不是django-redis。我会保留答案,因为更改缓存提供程序并使用此配置似乎已解决了问题。

您不需要unix:前缀,后端设置看起来很奇怪;

'default': {
    'BACKEND': 'redis_cache.RedisCache',
    'LOCATION': '/tmp/redis.sock',
    'OPTIONS': { ...