PHP for memcache Operation class

Source: Internet
Author: User

<span style= "FONT-SIZE:18PX;"    >class Mymemcache {private $memcache; /** * It is generally recommended that these 2 values be in the form of a constant */Public function __construct ($host = ' 192.102.1.8 ', $port = 6379) {$this->me        Mcache = new Memcache ();        $this->memcache->connect ($host, $port);    return $this->memcache;     }/** * Add adds a new key, but if the key already exists on the server, this operation will fail. * @param string $Key Key name * @param string $value value----can be an array, an object, a single value * @param int $timelift life time Add lifetime default is 0 Data does not expire */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 settings consistent key modifier key Name value * @param string $key Key Name * @param string $value key value * @param int $timeLife Life Week Period */Public function set ($key, $value, $timeLife) {if ($timeLife &Gt        0) {$retMes = $this->memcache->set ($key, $value, memcache_compressed, $timeLife);        } else {$retMes = $this->memcache->set ($key, $value);    } return $retMes; }/** * Gets key * @param string $key Key Name */Public function get ($key) {$retMes = $this->memcach        E->get ($key);    return $retMes; }/** * Delete a single key * @param string $key Key Name */Public Function DeleteKey ($key) {$retMes = $this        Memcache->delete ($key);    return $retMes;    }/** * Delete all keys */Public Function deleteAll () {return $this->memcache->flush (); }/** * Returns memcache Object * Memcache We only encapsulate a common part * take this object and you can call Memcache's own method directly * eg: $memcache->memcache Othermethods ()->getstats () GetStats Method not sealed */Public Function memcacheothermethods () {return $this->me    Mcache; }/** * Release * * Public function __destruct () {$this-> Memcache->close (); }}</span>

PHP for memcache Operation class

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.