国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP對(duì)memcache操作類

2020-03-22 20:25:44
字體:
供稿:網(wǎng)友
  • <span style="font-size:18px;">html' target='_blank'>class myMemcache {    private $memcache;    /**     * 一般建議這2個(gè)值做成常量的形式     */    public function __construct($host = '192.102.1.8', $port = 6379) {        $this->memcache = new Memcache();        $this->memcache->connect($host, $port);        return $this->memcache;    }    /**     * add  添加一個(gè)新key,但是如果 key已經(jīng)在服務(wù)端存在,此操作會(huì)失敗。     * @param string $Key    KEY名稱     * @param string $value  值----可以是數(shù)組,對(duì)象,單值     * @param int $timelift 生存時(shí)間   add生存時(shí)間默認(rèn)為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;    }    /**     * 刪除單個(gè)key     * @param string $key 鍵名     */    public function deleteKey($key) {        $retMes = $this->memcache->delete($key);        return $retMes;    }    /**     * 刪除所有key     */    public function deleteAll() {        return $this->memcache->flush();    }        /**     * 返回memcache對(duì)象     * memcache我們只封裝了常用的一部分     * 拿著這個(gè)對(duì)象就可以直接調(diào)用memcache自身方法     * eg:$memcache->memcacheOtherMethods()->getStats()   getStats方法沒封     */    public function memcacheOtherMethods() {        return $this->memcache;    }    /**     * 釋放     */    public function __destruct() {        $this->memcache->close();    }}</span>

    PHP編程

    鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

  • 發(fā)表評(píng)論 共有條評(píng)論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 密山市| 太和县| 称多县| 商城县| 弥渡县| 万年县| 德江县| 江都市| 卓资县| 弋阳县| 南郑县| 繁峙县| 中西区| 楚雄市| 常德市| 钦州市| 进贤县| 噶尔县| 松溪县| 汝州市| 衢州市| 辰溪县| 蒲城县| 台南市| 盈江县| 梓潼县| 含山县| 江山市| 石景山区| 内乡县| 嫩江县| 德保县| 松原市| 左贡县| 福安市| 琼海市| 赤壁市| 郯城县| 青冈县| 邛崃市| 玉溪市|