settings.py中文件内设置如下:

  

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':1000}
# 'PASSWORD':"密码"
}
},
'sniffcpcssocks':{
'BACKEND':'django_redis.cache.RedisCache',
'LOCATION':'redis://127.0.0.1:6379',
'OPTIONS':{
'CLIENT_CLASS':'django_redis.client.DefaultClient',
'CONNECTION_POOL_KWARGS':{'max_connections':1000}
# 'PASSWORD':"密码"
}
}
}

views.py文件中导入模块

 

from django_redis import get_redis_connection
from django.views.decorators.cache import cache_page

def showredispool():

conn = get_redis_connection('sniffcpcssocks')

conn.hset('name','pwd','nickname')

return HttpResponse('....')

from django.views.decorators.cache import cache_page
#此乃装饰器方法设置缓存的默认生命周期的方法
@cache_page(60*15)
# 缓存存在时间60秒*15
def showredispool(request):

conn = get_redis_connection('sniffcpcssocks')

conn.hset('name','pwd','nickname')

return HttpResponse('....')


相关文章:

  • 2021-12-30
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2021-04-08
  • 2021-04-12
猜你喜欢
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-08-08
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案