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

标签 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 异常,表示连接期间发生错误。关于此配置的问题有什么想法吗?

附言我的 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/

相关文章:

django - 如何让下拉选择从 Django 模型填充模板中的 DataTables 表?

python - Django动态CSS实现

python - mod_wsgi 启动时速度过慢?

Redis 不保留排序集中的精度

python - 如何在redis缓存中使用django-redis hset操作

database - 如何使用Rust从RediSearch检索数据?

django - 我在哪里放置代码以将数据从数据库推送到 django-redis 的 redis?

python - django 二进制文件下载在浏览器中损坏

django - 使用缓存以及将其用于Django中4000-10000个数据行的单个页面是一个好主意吗?

Django 休息框架 : Pickle Response