我正在尝试使用 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
异常,表示连接期间发生错误。关于此配置的问题有什么想法吗?
附言我的 Django 版本是 1.5.1
,django-redis 是 3.3
,hiredis 是 0.0.1
。
最佳答案
编辑:显然我读错了缓存提供程序,下面的答案是 django-redis-cache
的解决方案,而不是 django-redis
。不过,我会让答案保留下来,因为更改缓存提供程序并使用此配置似乎已经解决了问题。
你应该不需要unix:
前缀,后端设置看起来很奇怪;
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': '/tmp/redis.sock',
'OPTIONS': { ...
关于Django-redis 配置使用套接字而不是 TCP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17552123/