转:http://timyang.net/programming/memcache-mutex/
http://www.cnblogs.com/sunli/archive/2010/07/27/cache_key_mutex.html
http://www.cnblogs.com/jackluo/p/3726264.html
http://zhidao.baidu.com/link?url=t1A4ezhlNBYCBegjV0Itx1732ciWo6wb495QkalW0bSKxvHSX2UV5FHO44_tT4Fvtl3DGK7hQBvF677kGp4TKLRJ25211-lYpcKLjQCV9v3
http://blog.csdn.net/dizzthxl/article/details/8498813
http://www.dewen.io/q/10230
http://hudeyong926.iteye.com/blog/1463992
http://san-yun.iteye.com/blog/1602661
http://blog.jobbole.com/88096/
http://segmentfault.com/q/1010000000215640
http://php.net/manual/zh/memcached.cas.php
1 <?php
2 $conn=mysql_connect("localhost","root","root");
3 $db=mysql_select_db("qg");
4 $memcache=new Memcache();
5 $memcache->connect("127.0.0.1",11211) or die("connectfailed");
6 $key="pro_1";
7 $addtime=time();
8 $qgnum=$memcache->get($key);
9 if($qgnum==""){
10 $memcache->set($key,1,0,600);
11 $qgnum=1;
12 }else{
13 $qgnum=$qgnum+1;
14 $memcache->set($key,$qgnum,0,600);
15 }
16 echo "qgnum=>".$qgnum;
17 if($qgnum<=10){
18 $sql="select *from product where product_id=1 and storenum>0";
19 echo $sql."<br>";
20 $query=mysql_query($sql);
21 $row=mysql_fetch_assoc($query);
22 if($row["storenum"]>0){
23 $sql2="update product set storenum=storenum-1,ordernum=ordernum+1 where product_id=1";
24 echo $sql2."<br>";
25 mysql_query($sql2);
26 $sql3="insert into `order` set product_id=1,addtime='$addtime'";
27 echo $sql3."<br>";
28 mysql_query($sql3);
29 }
30
31 }