以组件的方式,添加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('....')

猜你喜欢

转载自www.cnblogs.com/saintdingspage/p/8974625.html