Use of memcached

Source: Internet
Author: User
Basic Use Method

 
  Addserver (' 127.0.0.1 ', 11211);p Rint_r ($m->getstats ()); echo "
";p Rint_r ($m->getversion ()); echo"
"; $data = Array ( ' key ' = ' value ', ' key2 ' = ' value2 ');//$m->setmulti ($data, n); $result = $m Getmulti (Array (' key ', ' Key2 ')), $m->deletemulti (' key ', ' Key2 ');//print_r ($result); Echo $m->get (' key ') echo $m->getresultcode (), Echo $m->getresultmessage (),//$m->add (' Mkey ', ' mvalue ', +);//$m->replace (' Mkey ', ' mvalue2 ', 1),//$m->flush (),//$m->set (' num ', ' n '),//$m->increment (' num ', 5); $m->decrement (' Num ', 5); Echo $m->get (' num '); $m->flush ();

Package class:

 Type) {$this->error = ' No '. $this->type;        return false;        } else {$this->m = new $this->type;    }} Public Function Addserver ($arr) {$this->m->addservers ($arr);        The Public function s ($key, $value = ", $time = NULL) {$number = Func_num_args ();        if ($number = = 1) {//get operation return $this->get ($key); } else if ($number >= 2) {if ($value = = = NULL) {//delete Operation $this->delete (            $key);            } else {//set operation $this->set ($key, $value, $time); }}} Private function set ($key, $value, $time = null) {if ($time = = = null) {$time = $thi        s->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;    }/** * Delete * @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; }}

Use of encapsulation classes:

 
  Addserver (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 ');

The above describes the use of memcached, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.