PHP MemCached cache application

Source: Internet
Author: User

Memcached is a high-performance distributed memory object Cache System for dynamic Web applications to reduce database load. It caches data and objects in the memory to reduce the number of times the database is read, so as to provide dynamic, database-driven website speed. Memcached is based on a hashmap that stores key/value pairs. Its daemon is written in C, but the client can write it in any language.

What is memcached? Memcached is a high-performance distributed memory object Cache System for dynamic web applications to reduce the database tutorial load. It caches data and objects in the memory to reduce the number of times the database is read, so as to provide dynamic, database-driven website speed. Memcached is based on a hashmap that stores key/value pairs. Its daemon is written in c, but the client can write it in any language and communicate with the daemon through memcached protocol. However, it does not provide redundancy (for example, copying its hashmap entries). When a server s stops running or crashes, all key/value pairs stored on s will be lost. Developed by danga interactive, memcached improves the access speed of livejournal.com. The number of dynamic page views per second on the lj is several thousand, and the number of users is 7 million. Memcached greatly reduces the database load and makes it easier to allocate resources for faster access.

Common memcache Methods

Memcache: add-add a value. if it already exists, false is returned.
Memcache: addserver-add an available server address
Memcache: close-close a memcache object
Memcache: connect-create a memcache object
Memcache: debug-control debugging
Memcache: decrement-deletes the value of a saved key.
Memcache: delete-delete a key value
Memcache: flush-Clear All cached data
Memcache: get-get a key value
Memcache: getextendedstats-obtains the running system statistics of all processes in the process pool.
Memcache: getserverstatus-get the parameters of the running server
Memcache: getstats-return some running statistics of the server
Memcache: getversion-returns the version information of the running memcache.
Memcache: increment-adds the value of a saved key.
Memcache: pconnect-creates a persistent connection object for memcache.
Memcache: replace-r: overwrites an existing key.
Memcache: set-Add a value. if it already exists, overwrite it.
Memcache: setcompressthreshold-compresses data larger than a certain size
Memcache: setserverparams-Modify server parameters at runtime

Memcache method usage

The Code is as follows:

<? Php tutorial
$ Memcache = new memcache;
$ Memcache-> connect ('127. 0.0.1 ', 127) or die ("connection failed ");
$ Memcache-> set ('name', 'zhang san ');
$ Val = $ memcache-> get ('name ');
?>

Note: The complete version of the set Method, set (key name, key value, whether to compress, retention time)

The Code is as follows:

<? Php
$ Memcache = new memcache;
$ Memcache-> connect ('127. 0.0.1 ', 127) or die ("connection failed ");
$ Memcache-> set ('name', array ('one', 'two '));
$ Val = $ memcache-> get ('name ');
Print_r ($ val );
$ Memcache-> close ();
?>

 


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.