1. Add expansion pack
2. Add
3. Procedure
//Create a mem object instance
$mem=new Memcache;
If(!$mem->connect("10.18.110.213",11211)){
die('Connection failed!');
}
//Add
//1. Add a string
/* if($mem->set('key1',"beijing",MEMCACHE_COMPRESSED,60)){
echo 'Add ok';
}*/
//2.Add value
/* if($mem->set('key1',100,MEMCACHE_COMPRESSED,60)){
echo 'Add ok';
}*/
//3.Add array
//When adding the array, as needed. I hope the serial number will be put into ,
//serialize<=>unserialize, if needed, you can also json_encode <=> json_decode
$arr=array("bj",'tj');
If($mem->set('key1',$arr,MEMCACHE_COMPRESSED,time()+31*3600*24)){
echo 'Add array ok99111';
}
//4.Add object
/* class Dog{
public $name;
public $age;
public function __construct($name,$age){
$this->name=$name;
$this->age=$age;
}
}
$dog1=new Dog('puppy',50);
If($mem->set('key1',$dog1,MEMCACHE_COMPRESSED,60)){
echo 'Add object ok';
}*/
//5.Add null Boolean value
/* if($mem->set('key1',false,MEMCACHE_COMPRESSED,60)){
echo 'Add boolean ok';
}*/
//6. Put the resource type.
/* $con=mysql_connect("127.0.0.1","root","root");
If(!$con){
die('Failed to connect to database');
}
var_dump($con);
echo "
";
If($mem->set('key1',$con,MEMCACHE_COMPRESSED,60)){
echo 'Add resource ok';
}*/
//Query
$val=$mem->get('key1');
//Modify
//You can use replace
If($mem->replace("key11",'hello',MEMCACHE_COMPRESSED,60)){
echo 'replace ok';
}else{
echo 'replace no ok';
}
//Delete
echo "
";
If($mem->delete('key14')){
echo 'key14 delete';
}else{
echo 'key14 does not exist';
}
1. The data of mem service is not synchronized, the data is distributed
2. What data is put into which memcached is determined by the mem object of the client
3. When executing addServer, it does not connect to the mem service immediately, but determines which mem service to connect to after calculation and hashing. Therefore, when you add a large number of servers to the connection pool, there is no extra overhead