memcache
来源:互联网 发布:淘宝网灯饰 编辑:程序博客网 时间:2024/06/10 02:41
<?phpdefined('BASEPATH') OR exit('No direct script access allowed');class Welcome extends CI_Controller { public function index() { $pdo=new PDO('mysql:host=localhost;dbname=text','root','root'); $pdo->exec("set names utf8"); $data=$pdo->query("select * from blog"); $this->load->vars('data',$data); $this->load->view('index.html'); } public function show() { $pdo=new PDO('mysql:host=localhost;dbname=text','root','root'); $pdo->exec("set names utf8"); $id=$_GET['id']; $mem=new Memcache; $mem->connect('127.0.0.1',11211); $num=$mem->get($id); if($num){ //之前存在 每次访问+1 $num++; $mem->set($id,$num); if($num>5){ //直接从memcache中取出数据 $str=$mem->get('data'.$id); echo $str; }elseif($num==5){ //取出数据存到memache中 $data=$pdo->query("select * from blog where id=$id")->fetch(PDO::FETCH_ASSOC); $str=json_encode($data); $mem->set('data'.$id,$str); echo $str; }else{ $data=$pdo->query("select * from blog where id=$id")->fetch(PDO::FETCH_ASSOC); $str=json_encode($data); echo $str; } }else{ //第一次查询 $mem->set($id,1); $data=$pdo->query("select * from blog where id=$id")->fetch(PDO::FETCH_ASSOC); echo json_encode($data); } }}
0 0
- Memcache
- MemCache
- Memcache
- Memcache
- Memcache
- memcache
- Memcache
- Memcache
- memcache
- memcache
- memcache
- memcache
- Memcache
- MemCache
- memcache
- memcache
- Memcache
- Memcache
- HDU 5040 Instrusive(2014 ACM/ICPC Asia Regional Beijing Online )
- emacs快速启动--emacsclient
- 定位样式position的四种定位
- 烦死了。。。看慕课网上的一个视频关于一个选择数据库的问题,,,,该如何解决呢?
- nyist 769 乘数密码(扩展欧几里得求逆元)
- memcache
- HDU 1502 Regular Words(打表预处理dp)
- 3325顺序表应用2:多余元素删除之建表算法
- 八个Docker的真实应用场景
- linux命令行模式满屏如何翻页?
- 大数据可视化技术现状分析及技术实践
- linux下使用yum安装mysql详解
- 删除链表中的元素
- C++ Notes-Inheritance-03