Example
| The code is as follows |
Copy Code |
|
<?php
$mem = new Memcache;
$mem->connect (' 127.0.0.1 ', 11211) or die ("could not Connect");
$mem->set (' key ', ' This is a test! ', 0, 60);
$val = $mem->get (' key ');
Echo $val;
?> |
The application will do a class
| The code is as follows |
Copy Code |
|
Class Mcache
{
private static $server = Array (' 127.0.0.1 ', 11211);
private static $client = ' memcached '; Memcache or memcached
private static function Get_memcache ()
{
Static $memcache;
if (!is_object ($memcache))
{www.111cn.net
$memcache = self:: $client = = = ' memcached '? New Memcached (): New Memcache;
$memcache->addserver (self:: $server [0],self:: $server [1]);
}
return $memcache;
}
public static function set ($key, $value, $expire =600)
{
Self:: $client = = ' memcached '? Self::get_memcache ()->set ($key, $value, $expire)
: Self::get_memcache ()->set ($key, $value, memcache_compressed, $expire);
}
public static function Get ($key)
{
Return Self::get_memcache ()->get ($key);
}
}
Mcache::set (' Test_one ', ' Value_one ', 60); # SEC
Print_r (Mcache::get (' Test_one '));
|
PHP memcache Client Summary of all methods
The list of all methods for the Memcache function is as follows:
Memcache::add– adds a value and returns False if it already exists
memcache::addserver– add a server address to use
memcache::close– closes a Memcache object
memcache::connect– Create a Memcache object
memcache_debug– Control Debugging function
Memcache::d ecrement– to subtract values from a key that is saved
Memcache: Delete a key value:d elete–
memcache::flush– clears all cached data
memcache::get– gets a key value
memcache::getextendedstats– get run System statistics for all processes in the process pool
memcache::getserverstatus– get the parameters to run the server
memcache::getstats– returns some running statistics for the server
memcache::getversion– returns the version information of the running Memcache
memcache::increment– an addition to the value in a key that is saved
Memcache: Create a Memcache Persistent connection object:p connect–
Memcache::replace-Overwrite an existing key
memcache::set– Add a value, if it already exists, overwrite
memcache::setcompressthreshold– compression of data larger than a certain size
memcache::setserverparams– Modify server parameters at run time