Introduction to the Memcache method of php and application example-PHP source code

Source: Internet
Author: User
Ec (2); network development, especially in the development of web projects with high traffic volumes. Memcache is used to reduce data query operations to improve response speed. There are already many installed Memcache instances on the Internet. I will introduce some common memcache methods. Memcache: add a value. if it already exists, return falseMemcache: addServer add Memcache address Memcache: c script ec (2); script

Network development, especially for web projects with high traffic volumes. Memcache is used to reduce data query operations to improve response speed.
There are already many installed Memcache instances on the Internet. I will introduce some common memcache methods.
Memcache: add // add a value. if it already exists, false is returned.
Memcache: addServer // Add a Memcache address
Memcache: close // close a Memcache connection
Memcache: connect // open a connection to Memcache
Memcache: decrement // subtract the value of a saved key
Memcache: delete // delete the key value of a Memcache.
Memcache: flush // refresh the items saved on all Memcache instances (similar to deleting all saved items)
Memcache: get // get a key value from Memcache
Memcache: getExtendedStats // gets the running system statistics of all processes in the process pool.
Memcache: getServerStatus // get the parameters of the running server
Memcache: getStats // get the running status of the current Memcache Server
Memcache: getVersion // return the version information of the running Memcache.
Memcache: increment // Add the value of a saved key
Memcache: pconnect // open a persistent connection to Memcache
Memcache: replace // replace a project that already exists on the Memcache server (functions similar to Memcache: set)
Memcache: set // Add a value to Memcache. if it already exists, overwrite it.
Memcache: setCompressThreshold // compress data larger than a certain size
Memcache: setServerParams // modify server parameters during runtime
Below are some simple usage examples for your reference only:
$ Mem = new Memcache;
$ Mem-> connect ("127.0.0.1", 12000 );
// Memcache: The set method has four parameters: the first parameter is the key, the second parameter is the value, the third parameter is optional, indicating whether to compress and save, and the fourth parameter is optional, this parameter is used to set a time when an expiration date is automatically destroyed.
$ Mem-> set ('test', '000000', 123 );
// The function of the Memcache: add method is similar to that of the Memcache: set method. The difference is that if the return value of the Memcache: add method is false, the key already exists, and Memcache :: the set method is overwritten directly.
$ Mem-> add ('test', '000000', 123 );
// The Memcache: get method is used to obtain a key value. The Memcache: get method has a parameter that indicates the key.
$ Mem-> get ('test'); // The output is '20140901'
// The Memcache: replace method is used to override an existing key. The Memcache: replace method has four parameters, which are the same as the Memcache: set Method.
$ Mem-> replace ('test', '000000', 456 );
// The Memcache: delete method is used to delete a key value. The Memcache: delete method has two parameters. The first parameter indicates the key, and the second parameter is optional, the deletion delay time.
$ Mem-> delete ('test', 60 );
?>

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.