django-redis-cache

raw JSON →
3.0.1 verified Mon Apr 27 auth: no python

A Redis cache backend for Django, providing a simple and efficient way to use Redis as your cache store. Current version is 3.0.1. The library is stable with infrequent releases, mainly maintenance updates. It supports Django 2.2+.

pip install django-redis-cache
error ModuleNotFoundError: No module named 'redis_cache'
cause Installed wrong package or outdated import path.
fix
Run 'pip install django-redis-cache' and use 'import redis_cache'.
error ImproperlyConfigured: The cache backend 'redis_cache.RedisCache' does not exist
cause Misspelled BACKEND or using wrong library.
fix
Ensure you have installed django-redis-cache and set BACKEND = 'redis_cache.RedisCache'.
error redis.exceptions.ConnectionError: Error 10061 connecting to localhost:6379. No connection could be made because the target machine actively refused it.
cause Redis server is not running.
fix
Start Redis server using 'redis-server' or configure LOCATION to a running instance.
gotcha Do not confuse django-redis-cache with django-redis. They have different import paths and backends. django-redis-cache uses BACKEND = 'redis_cache.RedisCache' while django-redis uses 'django_redis.cache.RedisCache'.
fix Ensure you install the correct library and use the correct backend string.
breaking Version 3.0.0 renamed the package from 'redis_cache' to 'django-redis-cache'. The import path changed from 'redis_cache' to 'redis_cache'? Actually, the module name is still 'redis_cache', but the pip package changed. Ensure you use 'pip install django-redis-cache'.
fix If you previously installed 'redis-cache', you need to uninstall and install 'django-redis-cache'.
deprecated The 'redis_cache.cache.RedisCache' class is deprecated; use 'redis_cache.RedisCache' directly.
fix Update your CACHES settings: BACKEND = 'redis_cache.RedisCache'

Configure the Redis cache backend and use Django's cache API.

# settings.py
CACHES = {
    'default': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/1',
        'OPTIONS': {
            'CLIENT_CLASS': 'redis_cache.client.DefaultClient',
        }
    }
}

# Usage
from django.core.cache import cache
cache.set('my_key', 'hello', timeout=300)
print(cache.get('my_key'))