DjangoUsing Redis with Django - Caching Backend

Remarks

Using django-redis-cache or django-redis are both effective solutions for storing all cached items. While it is certainly possible for Redis to be setup directly as a SESSION_ENGINE, one effective strategy is to setup the caching (as above) and declare your default cache as a SESSION_ENGINE. While this is really the topic for another documentaiton article, its relevance leads to inclusion.

Simply add the following to settings.py:

SESSION_ENGINE = "django.contrib.sessions.backends.cache"

Using django-redis-cache

One potential implementation of Redis as a backend caching utility is the django-redis-cache package.

This example assumes you already have a Redis server operating.

$ pip install django-redis-cache

Edit your settings.py to include a CACHES object (see Django documentation on caching).

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION': 'localhost:6379',
        'OPTIONS': {
            'DB': 0,
        }
    }
}

Using django-redis

One potential implementation of Redis as a backend caching utility is the django-redis package.

This example assumes you already have a Redis server operating.

$ pip install django-redis

Edit your settings.py to include a CACHES object (see Django documentation on caching).

CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/1',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
        }
    }
}