标签:val nat django 游戏 mem 特点 简单 options redis
pip install redis
import redis
r = redis.Redis(host='127.0.0.1', port=6379, db=1)
import redis
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=10, max_connections=100)
r = redis.Redis(connection_pool=pool)
# 安装django-redis
pip install django-redis
# settings.py
# 将缓存存储位置配置到redis中
ACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"CONNECTION_POOL_KWARGS": {"max_connections": 100}
}
}
}
# views.py
# 操作cache模块直接操作缓存
from django.core.cache import cache
# 存放token,可以直接设置过期时间
cache.set('token', 'header.payload.signature', 10)
# 取出token
token = cache.get('token')
标签:val nat django 游戏 mem 特点 简单 options redis
原文地址:https://www.cnblogs.com/17vv/p/11979398.html