django-redis plugs Redis into Django as a cache and optional session store using redis-py URL connection strings. It offers pluggable clients, parsers, serializers, compression, and extra Redis-specific helpers.
Overview
django-redis is a cache backend package for Django applications that stores cache entries in Redis instead of local memory or databases. You point Django's CACHES setting at a Redis URL with TCP, TLS, or Unix socket forms and optional ACL credentials.
Beyond basic get and set, it supports Django session storage when configured as the session engine, infinite timeouts consistent with Django semantics, and helpers such as ttl, persist, expire, locks, key pattern scans, and atomic incr or set-nx style operations where appropriate.
Configuration hooks include custom compressors, pickle version, socket timeouts, mimicked memcached ignore-exceptions behavior, primary or secondary clients, and direct access to the underlying Redis client for advanced use. Tests can flush Redis in tearDown via get_redis_connection.
Requirements stated in the documentation are modern Python, Django, redis-py, and a compatible Redis server. Installation is through pip into an existing Django project rather than as standalone software.
Key features
- Redis-backed Django cache backend
- redis-py native URL connections
- Optional session storage backend
- Pluggable clients and serializers
- Optional value compression
- TTL and persist helpers
- Distributed lock helper
- Pattern key scan and delete
Use cases
- Django app caching on Redis
- Redis-backed Django sessions
- Shared cache across app servers
- Atomic counters in Django cache
- Custom Redis commands from Django