> For the complete documentation index, see [llms.txt](https://moluo.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://moluo.gitbook.io/notes/bian-cheng-xue-xi/python/django-rest-framework/11.8.drf-pei-zhi-redis-huan-cun.md).

# 11.8.drf配置redis缓存

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`
