PHP MemCached advanced cache application code

  • 2020-03-31 21:01:01
  • OfStack

Memcache common methods

Memcache::add - adds a value that returns false if it already exists
Memcache::addServer - add a server address available for use
Memcache::close - closes a Memcache object
Memcache::connect - create a Memcache object
Memcache::debug - controls debugging
Memcache::decrement - subtracts a value from a saved key
Memcache::delete - deletes a key value
Memcache::flush - clears all cached data
Memcache::get - gets a key value
Memcache: : getExtendedStats - access to all the processes running in process pool system statistics
Memcache: : getServerStatus - access to run the server parameter
Memcache::getStats - returns some running statistics for the server
Memcache::getVersion - returns the version information of the running Memcache
Memcache::increment - adds the values in a saved key
Memcache::pconnect - creates a Memcache persistent connection object
Memcache::replace - R overwrites an existing key
Memcache::set - adds a value, overwrites if it already exists
Memcache: : setCompressThreshold - greater than a certain size of data compression
Memcache: : setServerParams - modify the parameters of the server at runtime

The Memcache method is used

 
<?php 
$memcache = new memcache; 
$memcache->connect('127.0.0.1', 11211) or die(" The connection fails "); 
$memcache->set('name', ' Zhang SAN '); 
$val = $memcache->get('name'); 
?> 

Note: full version of set method,set(key name, key value, whether compressed or not, hold time)

 
<?php 
$memcache = new memcache; 
$memcache -> connect('127.0.0.1', 11211) or die(" The connection fails "); 
$memcache -> set('name', array(' a ',' two ')); 
$val = $memcache->get('name'); 
print_r($val); 
$memcache -> close(); 
?> 

Related articles: