memcached的使用

來源:互聯網
上載者:User
基本使用方法

addServer('127.0.0.1', 11211);print_r($m->getStats());echo "
";print_r($m->getVersion());echo "
";$data = array( 'key' => 'value', 'key2' => 'value2',);//$m->setMulti($data, 600);$result = $m->getMulti(array('key', 'key2'));$m->deleteMulti(array('key', 'key2'));//print_r($result);echo $m->get('key');echo $m->getResultCode();echo $m->getResultMessage();//$m->add('mkey', 'mvalue', 600);//$m->replace('mkey', 'mvalue2', 1);//$m->flush();//$m->set('num', 50, 600);//$m->increment('num', 5);$m->decrement('num', 5);echo $m->get('num');$m->flush();

封裝類:

type)) {            $this->error = 'No '.$this->type;            return false;        } else {            $this->m = new $this->type;        }    }    public function addServer($arr) {        $this->m->addServers($arr);    }    public function s($key, $value = '', $time = NULL) {        $number = func_num_args();        if ($number == 1) {            //get操作            return $this->get($key);        } else if ($number >= 2) {            if ($value === NULL) {                //delete操作                $this->delete($key);            } else {                //set操作                $this->set($key, $value, $time);            }        }    }    private function set($key, $value, $time = NULL) {        if ($time === NULL) {            $time = $this->time;        }        $this->m->set($key, $value, $time);        if ($this->debug) {            if ($this->m->getResultCode() != 0) {                return false;            }        }    }    private function get($key) {        $ret = $this->m->get($key);        if ($this->debug) {            if ($this->m->getResultCode() != 0) {                return false;            }        }        return $ret;    }    /**     * 刪除     * @param $key     */    private function delete($key) {        $this->m->delete($key);    }    public function getError() {        if ($this->error) {            return $this->error;        } else {            return $this->m->getResultMessage();        }    }    public function d($debug) {        $this->debug = $debug;    }}

封裝類的使用:

addServer(array(    array('127.0.0.1', 11211),));//$m->s('key', 'value', 1800);////$m->s('key', NULL);//echo $m->s('key');//echo $m->getError();$m->s('test', 'testvalue', 0);echo $m->s('test');echo "
";$m->s('test', NULL);echo $m->s('test');

以上就介紹了 memcached的使用,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

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