标签:scac options from 获取 安装 red request order response
import redis
POOL = redis.ConnectionPool(host='127.0.0.1', port=6379,password='1234',max_connections=1000)
import redis
from django.shortcuts import render,HttpResponse
from utils.redis_pool import POOL
def index(request):
conn = redis.Redis(connection_pool=POOL)
conn.hset('kopa', 'age', 18)
return HttpResponse('设置成功')
def order(request):
conn = redis.Redis(connection_pool=POOL)
conn.hget('kopa', 'age')
return HttpResponse('获取成功')
安装django-redis模块
setting中配置
# redis配置
CACHES = {
"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}
# "PASSWORD": "123",
}
}
}
views中
from django_redis import get_redis_connection
conn = get_redis_connection('default')
print(conn.hgetall('x'))
标签:scac options from 获取 安装 red request order response
原文地址:https://www.cnblogs.com/kp1995/p/10645214.html