<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