PHP operations on memcache

Source: Internet
Author: User
Spanstylefont-size: 18px; classmyMemcache {private $ memcache; *** it is generally recommended that these two values be made into constants * publicfunction _ construct ($ host192.102.1.8, $ port6379) {$ this-memcachenewMemcache (); $ this-memcache-connect ($ host, $ port );

Span style = font-size: 18px; class myMemcache {private $ memcache; /*** it is generally recommended that these two values be made into constants */public function _ construct ($ host = 192.102.1.8, $ port = 6379) {$ this-memcache = new Memcache (); $ this-memcache-connect ($ host, $ port );

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 consistent key to change the key name value * @ 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 ();}}

Related Article

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.