<span style="font-size:18px;">html' target='_blank'>class myMemcache { private $memcache; /** * 一般建議這2個值做成常量的形式 */ public function __construct($host = '192.102.1.8', $port = 6379) { $this->memcache = new Memcache(); $this->memcache->connect($host, $port); return $this->memcache; } /** * add 添加一個新key,但是如果 key已經(jīng)在服務(wù)端存在,此操作會失敗。 * @param string $Key KEY名稱 * @param string $value 值----可以是數(shù)組,對象,單值 * @param int $timelift 生存時間 add生存時間默認為0表示數(shù)據(jù)用不過期 */ public function add($key, $value, $timeLife) { if ($time > 0) { $retMes = $this->memcache->add($key, $value, MEMCACHE_COMPRESSED, $timeLife); } else { $retMes = $this->memcache->add($key, $value); } return $retMes; } /** * set設(shè)置一致key 修改鍵名的值 * @param string $key 鍵名 * @param string $value 鍵值 * @param int $timeLife 生命周期 */ public function set($key, $value, $timeLife) { if ($timeLife > 0) { $retMes = $this->memcache->set($key, $value, MEMCACHE_COMPRESSED, $timeLife); } else { $retMes = $this->memcache->set($key, $value); } return $retMes; } /** * 獲取key * @param string $key 鍵名 */ public function get($key) { $retMes = $this->memcache->get($key); return $retMes; } /** * 刪除單個key * @param string $key 鍵名 */ public function deleteKey($key) { $retMes = $this->memcache->delete($key); return $retMes; } /** * 刪除所有key */ public function deleteAll() { return $this->memcache->flush(); } /** * 返回memcache對象 * memcache我們只封裝了常用的一部分 * 拿著這個對象就可以直接調(diào)用memcache自身方法 * eg:$memcache->memcacheOtherMethods()->getStats() getStats方法沒封 */ public function memcacheOtherMethods() { return $this->memcache; } /** * 釋放 */ public function __destruct() { $this->memcache->close(); }}</span>
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。
新聞熱點
疑難解答
圖片精選