# django-redis

> Full featured redis cache backend for Django.

- **URL**: https://www.freshcrate.ai/projects/django-redis
- **Author**: Andrei Antoukh
- **Category**: Frameworks
- **Latest version**: `7.0.0` (2026-06-02)
- **License**: BSD-3-Clause
- **Source**: https://github.com/jazzband/django-redis
- **Language**: Python
- **GitHub**: 3,063 stars, 450 forks
- **Registry**: pypi (`django-redis`)
- **Tags**: `pypi`

## Description

==============================
Redis cache backend for Django
==============================

.. image:: https://jazzband.co/static/img/badge.svg
    :target: https://jazzband.co/
    :alt: Jazzband

.. image:: https://github.com/jazzband/django-redis/actions/workflows/ci.yml/badge.svg
   :target: https://github.com/jazzband/django-redis/actions/workflows/ci.yml
   :alt: GitHub Actions

.. image:: https://codecov.io/gh/jazzband/django-redis/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/jazzband/django-redis
   :alt: Coverage

.. image:: https://img.shields.io/pypi/v/django-redis.svg?style=flat
    :target: https://pypi.org/project/django-redis/

This is a `Jazzband <https://jazzband.co>`_ project. By contributing you agree
to abide by the `Contributor Code of Conduct
<https://jazzband.co/about/conduct>`_ and follow the `guidelines
<https://jazzband.co/about/guidelines>`_.

Introduction
------------

django-redis is a BSD licensed, full featured Redis cache and session backend
for Django.

Why use django-redis?
~~~~~~~~~~~~~~~~~~~~~

- Uses native redis-py url notation connection strings
- Pluggable clients
- Pluggable parsers
- Pluggable serializers
- Primary/secondary support in the default client
- Comprehensive test suite
- Used in production in several projects as cache and session storage
- Supports infinite timeouts
- Facilities for raw access to Redis client/connection pool
- Highly configurable (can emulate memcached exception behavior, for example)
- Unix sockets supported by default

Requirements
~~~~~~~~~~~~

- `Python`_ 3.9+
- `Django`_ 4.2+
- `redis-py`_ 4.0.2+
- `Redis server`_ 2.8+

.. _Python: https://www.python.org/downloads/
.. _Django: https://www.djangoproject.com/download/
.. _redis-py: https://pypi.org/project/redis/
.. _Redis server: https://redis.io/download

User guide
----------

Installation
~~~~~~~~~~~~

Install with pip:

.. code-block:: console

    $ python -m pip install django-redis

Configure as cache backend
~~~~~~~~~~~~~~~~~~~~~~~~~~

To start using django-redis, you should change your Django cache settings to
something like:

.. code-block:: python

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

django-redis uses the redis-py native URL notation for connection strings, it
allows better interoperability and has a connection string in more "standard"
way. Some examples:

- ``redis://[[username]:[password]]@localhost:6379/0``
- ``rediss://[[username]:[password]]@localhost:6379/0``
- ``unix://[[username]:[password]]@/path/to/socket.sock?db=0``

Three URL schemes are supported:

- ``redis://``: creates a normal TCP socket connection
- ``rediss://``: creates a SSL wrapped TCP socket connection
- ``unix://`` creates a Unix Domain Socket connection

There are several ways to specify a database number:

- A ``db`` querystring option, e.g. ``redis://localhost?db=0``
- If using the ``redis://`` scheme, the path argument of the URL, e.g.
  ``redis://localhost/0``

When using `Redis' ACLs <https://redis.io/topics/acl>`_, you will need to add the
username to the URL (and provide the password with the Cache ``OPTIONS``).
The login for the user ``django`` would look like this:

.. code-block:: python

    CACHES = {
        "default": {
            "BACKEND": "django_redis.cache.RedisCache",
            "LOCATION": "redis://django@localhost:6379/0",
            "OPTIONS": {
                "CLIENT_CLASS": "django_redis.client.DefaultClient",
                "PASSWORD": "mysecret"
            }
        }
    }

An alternative would be write both username and password into the URL:

.. code-block:: python

    CACHES = {
        "default": {
            "BACKEND": "django_redis.cache.RedisCache",
            "LOCATION": "redis://django:mysecret@localhost:6379/0",
            "OPTIONS": {
                "CLIENT_CLASS": "django_redis.client.DefaultClient",
            }
        }
    }

In some circumstances the password you should use to connect Redis
is not URL-safe, in this case you can escape it or just use the
convenience option in ``OPTIONS`` dict:

.. code-block:: python

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

Take care, that this option does not overwrites the password in the uri, so if
you have set the password in the uri, this settings will be ignored.

Configure as session backend
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Django can by default use any cache backend as session backend and you benefit
from that by using django-redis as backend for session storage without
installing any additio

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `7.0.0` | 2026-06-02 | High | django-redis 7.0.0 (2026-06-02) ===============================  Features --------  - Added the ability to pass redis username in the cache options ([#657](https://github.com/jazzband/django-redis/issues/657)) - `RedisCache` does not attempt to close clients which have not been initialized. ([#796](https://github.com/jazzband/django-redis/issues/796)) - Add sorted set operations (zadd, zrange, zrem, etc.) and mixins for RedisCache ([#797](https://github.com/jazzband/django-redis/issues/7 |
| `6.0.0` | 2026-04-21 | Low | Imported from PyPI (6.0.0) |
| `5.4.0` | 2023-10-01 | Low | django-redis 5.4.0 (2023-10-01) ===============================  Features --------  - Connection factory goes to cache options (`#680 <https://github.com/jazzband/django-redis/issues/680>`_)   Documentation -------------  - Added note in docs for correctly configuring hiredis parser when using redis-py version 5. (`#677 <https://github.com/jazzband/django-redis/issues/677>`_) |
| `5.3.0` | 2023-06-16 | Low | Features --------  - Add support for django 4 (`#627 <https://github.com/jazzband/django-redis/issues/627>`_)   Bug Fixes ---------  - Access `django_redis.cache.DJANGO_REDIS_SCAN_ITERSIZE` and `django_redis.client.herd.CACHE_HERD_TIMEOUT` in runtime to not read Django settings in import time. (`#638 <https://github.com/jazzband/django-redis/issues/638>`_) - Skipping pickle serializer test for django >= 4.2 (`#646 <https://github.com/jazzband/django-redis/issues/646>`_)   Miscellane |

## Citation

- HTML: https://www.freshcrate.ai/projects/django-redis
- Markdown: https://www.freshcrate.ai/projects/django-redis.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/django-redis/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
