PHP指令碼memcache類的源碼

來源:互聯網
上載者:User

標籤: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類的源碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.