安装Redis就不说了,src中make后在后台运行redis-server,pip安装redis
安装django-redis
$ sudo pip install django-redis
settings.py中添加:
CACHES = { "default": { "BACKEND": "redis_cache.cache.RedisCache", "LOCATION": "127.0.0.1:6379:1", "OPTIONS": { "CLIENT_CLASS": "redis_cache.client.DefaultClient", } } }
view.py:
# Create your views here. from django.http import HttpResponse from django.views.decorators.cache import cache_page from django.core.cache import cache from django.shortcuts import render_to_response @cache_page(60) def home(request): cache.set('my_key', 'hello, world!', 30) return render_to_response("index.html",{'name':cache.get('my_key')})
运行redis-server,然后运行redis-cli,输入MONITOR
命令看看redis是否工作,访问页面,可看到会打印信息应该就没错了
网友216.*.*.226[Seattle]2022-06-30 07:06
网友220.*.*.176[北京]2022-06-30 07:01
网友185.*.*.2[火星]2022-06-30 06:51
网友185.*.*.20[火星]2022-06-30 06:19
发表评论
亲~ 评论内容是必须的哟! o(∩_∩)o
昵称
邮箱
主页
评论