Home  >  Article  >  Backend Development  >  Sample PHP MemCached advanced caching application code

Sample PHP MemCached advanced caching application code

coldplay.xixi
coldplay.xixiforward
2020-07-24 17:34:442472browse

Sample PHP MemCached advanced caching application code

Memcache common methods

  • Memcache::add — Add a value, if it already exists, return false

  • Memcache::addServer — Add a server address for use

  • Memcache::close — Close a Memcache object

  • Memcache::connect — Create a Memcache object

  • Memcache::debug — Control the debugging function

  • Memcache::decrement — Save the Subtract the value in a key

  • Memcache::delete — Delete a key value

  • Memcache::flush — Clear all caches Data

  • Memcache::get — Get a key value

  • Memcache::getExtendedStats — Get 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 in a saved key

  • Memcache::pconnect — Create a Memcache persistent connection object

  • Memcache::replace — R overwrites an existing key Operations

  • Memcache::set — Add a value, or overwrite it if it already exists

  • Memcache::setCompressThreshold — For values ​​greater than a certain Compress large and small data

  • Memcache::setServerParams — Modify server parameters at runtime

Memcache method usage

The code is as follows:

<?php 
$memcache = new memcache; 
$memcache->connect(&#39;127.0.0.1&#39;, 11211) or die("连接失败"); 
$memcache->set(&#39;name&#39;, &#39;张三&#39;); 
$val = $memcache->get(&#39;name&#39;); 
?>

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

The code is as follows:

<?php 
$memcache = new memcache; 
$memcache -> connect(&#39;127.0.0.1&#39;, 11211) or die("连接失败"); 
$memcache -> set(&#39;name&#39;, array(&#39;一个&#39;,&#39;两个&#39;)); 
$val = $memcache->get(&#39;name&#39;); 
print_r($val); 
$memcache -> close(); 
?>

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of Sample PHP MemCached advanced caching application code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete