settings里面:


##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":"密码",
}
},
}

'''
default是连接池的名称,可以在往后面加连接池,名称可以修改
'''



views里面的使用:
import  redis
from django_redis import get_redis_connection
from django.shortcuts import HttpResponse

def index(request):
conn=get_redis_connection('default')#default是连接池的名称
return HttpResponse('连接成功')



相关文章:

  • 2021-11-19
  • 2021-08-26
  • 2022-12-23
  • 2021-10-30
  • 2021-06-20
  • 2021-10-15
  • 2021-10-23
  • 2021-06-07
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-08-17
  • 2022-02-26
  • 2021-05-21
  • 2022-12-23
相关资源
相似解决方案