django-redis

6.0.0 · active · verified Thu Apr 09

django-redis is a full-featured Redis cache backend for Django, providing robust integration with Redis as Django's caching system. The current version is 6.0.0, released in June 2025, and it typically sees several updates per year, following Django's release cycle.

Warnings

Install

Imports

Quickstart

To get started, configure the `CACHES` setting in your Django project's `settings.py` file to use `django_redis.cache.RedisCache` as the backend. Specify the Redis connection string in `LOCATION` and any desired `OPTIONS` like client class or serializer. Once configured, you can interact with the cache using Django's standard `django.core.cache.cache` object.

# settings.py
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            # For redis-py >= 5.0 with hiredis:
            # "PARSER_CLASS": "redis.connection.HiredisParser",
            "SERIALIZER": "django_redis.serializers.json.JSONSerializer" # Example of changing serializer
        }
    }
}

# app_name/views.py or similar
from django.core.cache import cache

def my_view(request):
    value = cache.get('my_key')
    if value is None:
        value = 'data_from_db'
        cache.set('my_key', value, timeout=300) # Cache for 5 minutes
    return f"<h1>Cached Value: {value}</h1>"

view raw JSON →