Home >Backend Development >PHP Tutorial >PHP MemCached advanced caching application code

PHP MemCached advanced caching application code

高洛峰
高洛峰Original
2016-12-30 13:32:511130browse

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 — perform a subtraction operation on the value in a saved key
Memcache::delete — Delete a key value
Memcache::flush — Clear all cached data
Memcache::get — Get a key value
Memcache::getExtendedStats — Get all processes in the process pool Running system statistics
Memcache::getServerStatus — Get the parameters of the running server
Memcache::getStats — Return some running statistics of the server
Memcache::getVersion — Return the version information of the running Memcache
Memcache::increment — Add 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 if it already exists
Memcache::setCompressThreshold — Compress data larger than a certain size
Memcache::setServerParams — Modify the server at runtime Parameters

Memcache method usage

<?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, retention time)

<?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(); 
?>

More PHP For articles related to MemCached advanced caching application code, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn