抢购代码留存
//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);
}
}
?>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步