# 11.8.drf配置redis缓存

django-redis

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

## User guide

### Installation

Install with pip:

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

```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://[:password]@localhost:6379/0`
* `rediss://[:password]@localhost:6379/0`
* `unix://[:password]@/path/to/socket.sock?db=0`
