国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
    主站蜘蛛池模板: 屏山县| 电白县| 奉贤区| 天台县| 长子县| 古浪县| 新蔡县| 陵川县| 长垣县| 资源县| 寻乌县| 东海县| 梁山县| 泰州市| 新巴尔虎左旗| 顺义区| 梁平县| 青岛市| 绥棱县| 博乐市| 黄骅市| 平顶山市| 武鸣县| 成都市| 县级市| 桓台县| 广河县| 辽中县| 泰来县| 蒙城县| 迁西县| 富锦市| 五峰| 福安市| 宜丰县| 潞城市| 霍林郭勒市| 安义县| 上高县| 肇州县| 肇州县|