标签:ref set 1.0 mem session 文件 option engine ESS
SESSION_ENGINE=‘django.contrib.sessions.backends.db‘ # default 保存到数据库中,依赖 ‘django.contrib.sessions‘,app与数据库交互
SESSION_ENGINE=‘django.contrib.sessions.backends.cache‘ #缓存到内存,默认是本机内存,django-redis可以存储到redis中
SESSION_ENGINE=‘django.contrib.sessions.backends.cached_db‘ # 同时保存到数据库和缓存中
使用django-redis包
https://django-redis-chs.readthedocs.io/zh_CN/latest/ 文档地址
安装pip install django-redis
作为 cache backend 使用配置
#为了使用 django-redis , 你应该将你的 django cache setting 改成这样:
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}
3.作为session backend使用配置
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"
各个组件的版本,redis django-redis版本过高都不行
celery 4.2.1
Django 1.8.2
django-redis 3.8.4
django-tinymce 2.7.0
itsdangerous 1.1.0
kombu 4.2.2.post1
Pillow 5.4.1
pip 18.1
PyMySQL 0.9.3
redis 2.10.0
安装
pip install django-redis-sessions==0.5.6
设置
SESSION_ENGINE = ‘redis_sessions.session‘
SESSION_REDIS_HOST = ‘localhost‘
SESSION_REDIS_PORT = 6379
SESSION_REDIS_DB = 2
SESSION_REDIS_PASSWORD = ‘‘
SESSION_REDIS_PREFIX = ‘session‘
会话还支持文件、纯cookie、Memcached、Redis等方式存储
标签:ref set 1.0 mem session 文件 option engine ESS
原文地址:https://www.cnblogs.com/endurance9/p/10284792.html