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

Sample PHP MemCached advanced caching application code

coldplay.xixi
Release: 2023-04-09 11:06:01
forward
2532 people have browsed it

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;); 
?>
Copy after login

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

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!

Related labels:
source:jb51.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template