memcached用到的相关资料
1、安装:将memcached.exe程序复制到合理的位置:

2、启动:进入上一步的目录:
使用“管理员权限”启动cmd:

测试命令:


3、安装memcache扩展
memcache并不是php内置的功能,需要进行扩展(和GD扩展一样)
1) 下载memcache.dll文件(php_memcache.dll)
2)将php_memcache.dll文件复制到 php/ext目录下

3)修改php.ini的配置文件增加 extension=memcache.dll

测试一下:http://localhost/phpinfo.php

返回框架controller中使用详情:
<?php
namespace Home\Controller;
//use Think\Controller;
use Common\Tools\HomeController;
class IndexController extends HomeController {
public function index(){
/*使用memcached缓存数据*/
//给推荐商品设置一个key
S(array('type'=>'memcache','host'=>'localhost','port'=>11211));
$tuijian_key = md5("qiang_rec_hot_new");
$info = S($tuijian_key);
//var_dump($info);没有数据注意查看本机的memcached的服务详情,是否开启,端口号是否匹配
if(empty($info)){
echo "此时走数据库";
/*获取推荐商品信息*/
$goods = D('Goods');
$cdt['is_del'] = "不删除";
$cdt['is_sale'] = "上架";
//1、抢购的
$cdt_q = $cdt;
$cdt_q['is_qiang'] = "抢";
$info_qiang = $goods->where($cdt_q)->order('goods_id desc')->limit(5)->select();
//获得抢购的商品id信息
$ids_q = arrayToString($info_qiang,'goods_id');
//为memcache准备数据,把查询好的数据放到memecache中
$info['qiang'] = $info_qiang;
S($tuijian_key,$info);
}
//分配到模板
$this->assign('info_qiang',$info['qiang']);
/*获取分类信息 给模板显示*///使用公共引入HomeController
$this->display();
}
}
网友评论