Connecting to a database
The code is as follows |
Copy Code |
$memcache _obj = Memcache_connect ("localhost", 11211); Memcache_add ($memcache _obj, ' var_key ', ' Test variable ', false, 30); $memcache _obj->add (' Var_key ', ' Test variable ', false, 30); |
Instance 1
The code is as follows |
Copy Code |
<?php Connection $mem = new Memcache; $mem->connect ("127.0.0.1″, 11211) or Die" ("Could not Connect"); Display version $version = $mem->getversion (); echo "Memcached Server version:". $version. " <br> "; Save data $mem->set (' key1′, ' This is ', ', 0, 60); $val = $mem->get (' key1′); echo "Get Key1 Value:". $val. " <br> "; Replace data $mem->replace (' key1′, ' This is replace value ', 0, 60); $val = $mem->get (' key1′); echo "Get Key1 Value:". $val. "<br>"; Save Array $arr = Array (' AAA ', ' BBB ', ' CCC ', ' ddd '); $mem->set (' key2′, $arr, 0, 60); $val 2 = $mem->get (' key2′); echo "Get Key2 value:"; Print_r ($val 2); echo "<br>"; Delete data $mem->delete (' key1′); $val = $mem->get (' key1′); echo "Get Key1 Value:". $val. "<br>"; Clear All data $mem->flush (); $val 2 = $mem->get (' key2′); echo "Get Key2 value:"; Print_r ($val 2); echo "<br>"; Close connection $mem->close (); ?> |
The Memcache function library is in the PECL (PHP Extension Community Library), the main role is to build large capacity of the memory data temporary storage area
, in the distributed time the role manifests is very obvious, the network marketing training otherwise does not suggest uses.
Memcache::add-Adds a value that 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! [4 F8 C2 E, X
Memcache::d ecrement-subtraction of values in a key saved
Memcache::d elete-delete a key value
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 parameters for running the server
Memcache::getstats-Returns some running statistics for the server
Memcache::getversion-Returns the version information of the running Memcache
Memcache::increment-Add operations to the values in a key that is saved
Memcache::p Connect-Create a Memcache persistent connection object
Memcache::replace-Overwrite an existing key
Memcache::set-Adds a value that, if it already exists, is overridden
Memcache::setcompressthreshold-compresses data larger than a certain size
Memcache::setserverparams-Modify the server's parameters at run time