php memcache类
<?php /* * 2012-12-04 14:54 * @author 孤独求学人 */ class php_memcache{ protected $handle = null; protected $mem = null; private $host = ""; private $port = ""; private $timeout = 0; private $pconnect = false; public function __construct($host = '127.0.0.1',$port='11211',$timeout=0,$pconnect=false){ $this->host = $host; $this->port = $port; $this->timeout = $timeout; $this->pconnect = $pconnect; $this->mem = new Memcache(); } public function connect(){ if(!is_resource($this->handle)) { if($this->pconnect == false){ if(empty($this->host)){ return false; } if(empty($this->port)){ return false; } $handle = $this->mem->connect($this->host,$this->port); if(!$handle){ return false; }else{ $this->handle = $handle; } } } return $this->handle; } public function set($key,$val,$flag=false,$expire=0){ if(!$this->connect()) return false; $iFlage = 0; if($flag == true){ $iFlage = MEMCACHE_COMPRESSED; } return $this->mem->set($key,$val,$iFlage,$expire); } public function get($key){ if(!$this->connect()) return false; if (is_array($key)) { $dest = array(); foreach ($key as $subkey) { $val = $this->get($subkey); if (!($val === false)){ $dest[$subkey] = $val; } } return $dest; } else { return $this->mem->get($key); } } public function replace($key,$val,$flag=false,$expire=0){ if(!$this->connect()) return false; $iFlage = 0; if($flag == true){ $iFlage = MEMCACHE_COMPRESSED; } return $this->mem->replace($key,$val,$iFlage,$expire); } public function delete($key,$time=0){ if(!$this->connect()) return false; return $this->mem->delete($key,$time); } public function flush(){ if(!$this->connect()) return false; return $this->mem->flush(); } public function incr($key,$val=1){ if(!$this->connect()) return false; return $this->mem->increment($key,$val); } public function decr($key,$val=1){ if(!$this->connect()) return false; return $this->mem->decrement($key,$val); } public function getVersion(){ if(!$this->connect()) return false; return $this->mem->getVersion(); } } ?>
« 敏捷开发 至理名言
|
究极程序员跨过的艰难六步»
热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(18)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(72)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)