[root@localhost src]# wget https://gist.githubusercontent.com/JimWestergren/3053250/raw/d9e279e31cbee4a1520f59108a4418ae396b2dde/index-with-redis.php
[root@localhost src]# chown php-fpm:php-fpm index-with-redis.php
[root@localhost src]# mv predis.php index-with-redis.php /data/www/blog
根据自己需求修改index-with-redis.php,修改如下:
$cf = 0; // set to 1 if you are using cloudflare
$debug = 1; // set to 1 if you wish to see execution time and cache actions
$display_powered_by_redis = 0; // set to 1 if you want to display a powered by redis message with execution time, see below
如果你正在使用cloudflare,请设置cf = 1; ,
如果你想在页面上看到脚本执行时间和缓存加载时间,请设置$debug = 1; 浏览器最下方会显示this is cache:
display_powered_by_redis = 1表示显示powered_by信息。如下图右下角图标:
替换index.php
[root@localhost blog]# mv index.php index.php.bak
[root@localhost blog]# mv index-with-redis.php index.php
缓存问题
index-with-redis.php中有注释
- appending a ?c=y to a url deletes the entire cache of the domain, only works when you are logged in
- appending a ?r=y to a url deletes the cache of that url
- submitting a comment deletes the cache of that page
- refreshing (f5) a page deletes the cache of that page
登录后台网站url后面加上?c=y即可刷新整个网站
可以在网站页面后面加上?r=y即可手工刷新
提交评论会自动刷新页面
刷新(f5)页面也可以刷新页面
刷新网页查看缓存效果,查看源代码
360浏览器页面最下角会显示类似:this is a cache: 0.04534
F5刷新页面缓存时间会变化
注意事项
1、注意,Wordpress Redis缓存PHP版本在5.3以上
2、Wordpress Redis缓存加速效果无疑是明显的,特别页面多访问大的网站博客,在使用Wordpress Redis缓存加速时请禁止其它的所有缓存插件,以免造成不必要的冲突。
Ubuntu 14.04下Redis安装及简单测试