//phpinfo();
header("Content-type:text/html;charset=utf-8");
include ‘Mysql.class.php‘;
$redis = new Redis();
$redis->connect(‘127.0.0.1‘, 6379);
$id = $_GET[‘id‘]?$_GET[‘id‘]:1;
if($_GET["action"] == "add"){
$mysql = new Mysql("localhost","root","root","qhb");
$good = $mysql->getRow("select * from good where id=".$id);
if(is_array($good) && $good[‘kucun‘]>0){
for($i=0;$i<$good[‘kucun‘];$i++){
$redis->lPush("good".$good[‘id‘],1);
}
}
echo "抢购写入缓存";
}elseif($_GET[‘action‘] = "qiang"){
$len = $redis->Lsize("good".$id);
if($len && $ll = $redis->lPop("good".$id)){
$data = array(
‘user_id‘=>rand(),
‘good_id‘=>$id
);
$mysql = new Mysql("localhost","root","root","qhb");
$mysql->insert("gouwuche",$data);
}
}
?>