PHP using Memcache caching technology to introduce a simple

Source: Internet
Author: User
Tags flush

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.