前提:CentOS下准备好Redis数据库环境click me
一 摘要
1.pip下载redis扩展库
2.根据django-redis 中文文档在设置文件中配置redis数据库
二 步骤
1.pip下载redis扩展库
pip install django-redis
2.根据django-redis 中文文档在设置文件中配置redis数据库
https://django-redis-chs.readthedocs.io/zh_CN/latest/
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://121.4.134.212:6379/0",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"PASSWORD": "mysecret"
}
},
"session": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://121.4.134.212:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"PASSWORD": "mysecret"
}
},
}
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "session"