zoukankan      html  css  js  c++  java
  • 秒杀代码

        public function redis(){
            $store=100;
            $redis=new Redis();
            $result=$redis->connect('127.0.0.1',6379);
            $res=$redis->llen('goods_store');
            echo $res;
            $count=$store-$res;
            for($i=0;$i<$count;$i++){
                $redis->lpush('goods_store',1);
            }
            echo $redis->llen('goods_store');
        }
    
        public function go(){
            $redis=new Redis();
            $result=$redis->connect('127.0.0.1',6379);
            $count=$redis->lpop('goods_store');
            if(!$count){
                $this->insertLog('error:no store redis');
                echo "秒杀结束";
                exit;
            }
     
            //库存减少
            
            $is_true=M("Store","ih_")->where('id=1 and number>0')->setDec('number');
            
            if($is_true){
                $this->insertLog('库存减少成功'.I("user_id"),1);
                echo "秒杀成功";
            }else{
                $this->insertLog('库存减少失败'.I("user_id"),2);
                echo "秒杀失败";
            }
    
    
        }
    
       public function insertLog($event,$type=0){
             $model=M("Log","ih_");
             $data["event"]=$event;
             $data["type"]=$type;
             $model->add($data);
        }
    

      

  • 相关阅读:
    JS运算符
    JS基础
    0507-弹性盒子
    0506css3(2D、3D)动画
    CSS3边框
    0503-格式与布局
    0502-边框边界
    0502-其他html标签
    0428-专题块状元素
    mysql 数据库学习
  • 原文地址:https://www.cnblogs.com/zgaspnet/p/8464129.html
Copyright © 2011-2022 走看看