PHP operations on memcache
Class myMemcache {private $ memcache;/*** it is generally recommended that these two values be made into constants */public function _ construct ($ host = '2017. 102.1.8 ', $ port = 6379) {$ this-> memcache = new Memcache (); $ this-> memcache-> connect ($ host, $ port ); return $ this-> memcache;}/*** add a new key, but this operation fails if the key already exists on the server. * @ Param string $ Key KEY name * @ param string $ value ---- it can be an array, object, single value * @ param int $ timelift life time add default life time is 0 indicates data is not expired */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? Change the key name value with the same key * @ param string $ key name * @ param string $ value key value * @ param int $ timeLife lifecycle */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 ;} /*** get key * @ param string $ key name */public function get ($ key) {$ retMes = $ this-> memcache-> get ($ key ); return $ retMes;}/*** delete a single key * @ param string $ key name */public function deleteKey ($ key) {$ retMes = $ this-> memcache-> delete ($ key); return $ retMes;}/*** delete all keys */public function deleteAll () {return $ this-> memcache-> flush ();} /*** return memcache object * memcache we only encapsulate a common part * with this object, you can directly call the memcache method * eg: $ memcache-> memcacheOtherMethods () -> The getStats () getStats method is not blocked */public function memcacheOtherMethods () {return $ this-> memcache;}/*** release */public function _ destruct () {$ this-> memcache-> close ();}}