PHP operations on memcache and phpmemcache

Source: Internet
Author: User

PHP operations on memcache and phpmemcache

<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 = '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 () ;}</span>


How does php operate memcache?

To use memcached in PHP first download the memcached-client.php, after downloading the memcached-client.php, you can operate the memcached service through the class "memcached" in this file. In fact, code calls are very simple. The main methods used are add (), get (), replace (), and delete (). The methods are described as follows: add ($ key, $ val, $ exp = 0) writes an object to memcached. $ key is the unique identifier of the object. $ val is the data of the written object. $ exp is the expiration time, in seconds, the default value is unlimited; get ($ key) www.phpnewer.com/index.php/Tszj/detail/id/404

The memcache module cannot be found in php.

1. Write a phpinfo file to view the file <? Php phpinfo ();?>
2. Search for php. ini in phpinfo and find the location of php. ini. Make sure that the modified php. ini and the actually running php. ini are a file.
3. Check whether the ext directory in php. ini contains the php_memcache.dll directory for you.
4. Check whether the ext directory of php is in the system environment variable.

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.