PHP 對 memcache操作類,phpmemcache操作類

來源:互聯網
上載者:User

PHP 對 memcache操作類,phpmemcache操作類

<span style="font-size:18px;">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已經在服務端存在,此操作會失敗。     * @param string $Key    KEY名稱     * @param string $value  值----可以是數組,對象,單值     * @param int $timelift 存留時間   add存留時間預設為0表示資料用不到期     */    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設置一致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我們只封裝了常用的一部分     * 拿著這個對象就可以直接調用memcache自身方法     * eg:$memcache->memcacheOtherMethods()->getStats()   getStats方法沒封     */    public function memcacheOtherMethods() {        return $this->memcache;    }    /**     * 釋放     */    public function __destruct() {        $this->memcache->close();    }}</span>


php怎操作memcache

在PHP中要使用memcached首先下載 memcached-client.php,在下載了memcached-client.php 之後,就可以通過這個檔案中的類“memcached”對 memcached 服務進行操作了。其實代碼調用非常簡單,主要會用到的方法有 add()、get()、replace() 和 delete(),方法說明如下:add ($key, $val, $exp = 0)往 memcached 中寫入對象,$key 是對象的唯一識別碼,$val 是寫入的對象資料,$exp 為到期時間,單位為秒,預設為不限時間;get ($key)www.phpnewer.com/index.php/Tszj/detail/id/404
 
php找不到memcache模組

1.寫一個phpinfo查看檔案 <?php phpinfo();?>
2.然後在phpinfo裡面搜尋 php.ini 找到php.ini的位置,確認你修改的php.ini和實際啟動並執行php.ini是一個檔案。
3.檢測php.ini中的ext目錄是否為你放php_memcache.dll的目錄
4.檢測php的ext目錄是否在系統內容變數中。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.