Php operations on memcache cache

Source: Internet
Author: User
After the memcache service and php extensions are installed in the php operation on memcache cache, we can use php to operate on memcache for caching!

Summary of all PHP Memcache Client methods

The list of all memcache methods is as follows:

Memcache: add adds a value. if it already exists, false Memcache: addServer is returned. add a available server address Memcache: close to close a Memcache object Memcache:: connect. create a Memcache object memcache_debug. control and debug the function. Memcache: decrement. perform the subtraction operation on the values of a saved key. Memcache: delete a key value Memcache :: flush clear all cached data Memcache: get if a key value does not exist, falseMemcache: getExtendedStats is returned to retrieve the running system statistics of all processes in the process pool. Memcache :: getServerStatus obtains the parameter Memcache: getStats of the running server and returns some running statistics of the server. Memcache: getVersion returns the version information of the running Memcache. Memcache :: increment addition operation on the value of a saved key Memcache: pconnect create a persistent connection object for Memcache: replace-overwrite an existing key for Memcache:: set to add a value. if it already exists, overwrite Memcache: setCompressThreshold to compress Memcache: setServerParams for data larger than a certain size. modify server parameters during runtime.


Read and set cache code instances

 Connect ('2017. 0.0.1 ', 11211); // obtain the value of a variable. if the value of the returned variable exists, false $ var = $ memObj-> get ('test') is returned '); // Determine whether the cache exists. if no, connect to the database to obtain the variable and save it to the memcache server if (! $ Var) {// connect to the database... if the returned value is 'test .... '; $ var = 'test .... '; $ memObj-> set ('test', $ var); // The echo output in the test cache process indicates that the cache does not exist ..... ';} echo $ var;


Delete cache

 Connect ('1970. 0.0.1 ', 127); // delete the cache $ memObj-> delete ('test ');


Clear Cache

 Connect ('1970. 0.0.1 ', 127); $ memObj-> flush ();


Close connection

 Connect ('1970. 0.0.1 ', 127); $ memObj-> flush (); $ memObj-> close ();


After combined with php, the memcache value can be common php variables such as common variables, arrays, and objects.

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.