django-redis配置

在redis中保存cache和session

1.安装redis

pip install django-redis

 

2.settings中设置cache&session

# 设置django中CACHE默认的保存位置
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        # 设置为redis所在, 以及所用库序列
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    }
}

# 设置session保存在cache中
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"

 

转载于:https://www.cnblogs.com/jrri/p/11537497.html

你可能感兴趣的:(数据库,python)