11.8.drf配置redis缓存

django-redis

使用指南请参考https://github.com/jazzband/django-redis

User guide

Installation

Install with pip:

$ 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:

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://[:password]@localhost:6379/0

  • rediss://[:password]@localhost:6379/0

  • unix://[:password]@/path/to/socket.sock?db=0

Last updated

Was this helpful?