Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15320

Django-redis configuration to use socket rather than TCP

I'm attempting to use django-redis using Unix sockets rather than a TCP connection:

This is the settings.py configuration:

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',
        },
    },
}

and this is an extract of the redis config file at /etc/redis/6379.conf:

# 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

Still I receive a ConnectionInterrumped exception, which stands for an error during connection. Any ideas about what this configuration's issue is?

P.S. My Django version is 1.5.1, django-redis is 3.3 and hiredis is 0.0.1.

Upvotes: 2

Views: 2399

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 181057

EDIT: Apparently I read the cache provider wrong, the below answer is the solution for django-redis-cache, not django-redis. I'll let the answer remain though, since changing cache provider and using this config seems to have solved the problem.

You should not need the unix: prefix, and the backend setting looks strange;

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

Upvotes: 2

Related Questions