Home > Article > Backend Development > 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('127.0.0.1', 11211) or die("连接失败"); $memcache->set('name', '张三'); $val = $memcache->get('name'); ?>
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('127.0.0.1', 11211) or die("连接失败"); $memcache -> set('name', array('一个','两个')); $val = $memcache->get('name'); 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!