-
- //Create a memcache object instance
- $memcache = new Memcache;
- if(!$memcache->connect("127.0.0.1",11211)){
- die('Connect Failed');
- }
- if($memcache->set('key1',"xian",MEMCACHE_COMPRESSED,60)){
- echo 'sucess!';
- }//Save the value, where the xian string is also Can be an array, object, but not a resource
- // bbs.it-home.org
- $val = $memcache->get('key1');//Query to get the value
- echo $val;
- $memcache- >replace('key1','beijing',MEMCACHE_COMPRESSED,60);//Modify
- $memcache->delete('key1');//Delete
- ?>
Copy code
Second Part, php memcached advanced caching application code
PHP MemCached advanced caching application
Memcache common methods:
-
- $memcache = new memcache;
- $memcache->connect('127.0.0.1', 11211) or die("Connection failed");
- $memcache->set( 'name', 'Zhang San');
- $val = $memcache->get('name');
- ?>
Copy code
Note: The complete version of the set method, set(key name , key value, whether to compress, retention time)
Example:
-
- $memcache = new memcache;
- $memcache -> connect('127.0.0.1', 11211) or die("Connection failed");
- $memcache -> set( 'name', array('one','two'));
- $val = $memcache->get('name');
- print_r($val);
- $memcache -> close();
- ?>
Copy code
|