[Django]-Django connection to Redis

5👍

You can use django-redis, which allows using Redis as the backend for Django’s cache framework. It supports connection pooling.

Basic usage:

# settings.py
CACHES = {
    'default': {
        'BACKEND': 'redis_cache.cache.RedisCache',
        'LOCATION': '127.0.0.1:6379:1',
    }
}

Then you can use it in your view code:

from django.core.cache import cache
cache.set('foo', 'bar')

For sadd you can use the raw Redis client:

>>> from django_redis import get_redis_connection
>>> con = get_redis_connection('default')
>>> con
<redis.client.Redis object at 0x2dc4510>
👤yprez

Leave a comment