zoukankan      html  css  js  c++  java
  • 抢购代码留存

    //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);
         }
     }
    ?>

  • 相关阅读:
    java23种设计模式(五)--组合模式
    elasticsearch删除
    Jedis
    Redis主从复制(含哨兵模式)
    Redis持久化
    Redis基本知识(含数据类型)
    Linux学习(含有常用命令集)
    深入Kafka
    Kafka消费者
    Kafka生产者
  • 原文地址:https://www.cnblogs.com/ylcms/p/7345088.html
Copyright © 2011-2022 走看看