freshcrate
Home > Frameworks > django-redis

django-redis

Full featured redis cache backend for Django.

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

Release History

VersionChangesUrgencyDate
6.0.0Imported from PyPI (6.0.0)Low4/21/2026
5.4.0django-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>`_)Low10/1/2023
5.3.0Features -------- - 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>`_) MiscellaneLow6/16/2023

Dependencies & License Audit

Loading dependencies...

Similar Packages

pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2
django-tasksA backport of Django's built in Tasks framework0.12.0