標籤:des style blog io ar color os sp on
<?php/** * @example $mem = new Memcached(); * @example $getCache = $mem->get(‘test‘); * @example MEMCACHE_HOST 主機 * @example MEMCACHE_PORT 連接埠 * @example MEMCACHE_TIMEOUT 緩衝時間 */class Memcached { private $memcache = null; /** * @desc 建構函式 */ public function __construct() { $this->memcache = new Memcache; $this->memcache->connect(MEMCACHE_HOST, MEMCACHE_PORT, MEMCACHE_TIMEOUT); } /** * 相容php4 */ public function Memcached() { $this->__construct(); } /** * @desc 根據key擷取Memcache的值 * @param string $name key名稱 * @return array or string */ public function get($name,$isJson = true) { $value = $this->memcache->get($name); if($isJson) $value = json_decode($value, true); return $value; } /** * 設定緩衝,如果存在就更新,不存在則添加,如果成功則返回 TRUE,失敗則返回 FALSE。 * @param string $name key名稱 * @param array or array $value value值 * @param boolean $ttl 是否壓縮 * @param int $ext1 用來設定一個到期自動銷毀的時間 * @return boolean */ public function set($name, $value, $ext1 = false, $ttl= 0) { return $this->memcache->set($name, $value, $ext1, $ttl); } /** * 添加緩衝,如果成功則返回 TRUE,失敗則返回 FALSE。 * @param string $name key名稱 * @param array or array $value value值 * @param boolean $ttl 是否壓縮 * @param int $ext1 用來設定一個到期自動銷毀的時間 * @return boolean */ public function add($name, $value, $ext1 = false, $ttl= 0) { return $this->memcache->add($name, $value , $ext1, $ttl); } /** * @desc 刪除緩衝,如果成功則返回 TRUE,失敗則返回 FALSE。 * @param string $name key名稱 * @return boolean */ public function delete($name) { return $this->memcache->delete($name); } /** * @desc 關閉一個Memcache對象 * @return blloean */ public function close() { return $this->memcache->close(); } /** * @desc Increment item‘s value (加法操作) * @param string $name * @param int $value Increment the item by value . Optional and defaults to 1. * @return type */ public function increment($name , $value) { return $this->memcache->increment($name, $vlaue); } /** * @desc decrement item‘s value (減法操作) * @param string $name * @param int $value decrement the item by value . Optional and defaults to 1. * @return type */ public function decrement($name , $value) { return $this->memcache->decrement($name, $vlaue); } /** * @desc 擷取進程池中所有進程的運行系統統計 * @return array */ public function getExtendedStats() { return $this->memcache->getExtendedStats(); } /** * @desc 返回伺服器的一些運行統計資訊 * @return array */ public function getStats() { return $this->memcache->getStats(); } /** * @desc 清空緩衝,如果成功則返回 TRUE,失敗則返回 FALSE。 * @return boolean */ public function flush() { return $this->memcache->flush(); }}?>
PHP指令碼memcache類的源碼