以组件的方式,添加redis_cache

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('....')


posted @ 2018-04-30 20:43  saintdingtheGreat  阅读(157)  评论(0编辑  收藏  举报