Redis PHP页面秒杀lpush

Redis  PHP页面秒杀lpush

现在tp5里面展示数据,然后查询前台a标签传来的值,然后接值,顺便判断一下,数据的总数是不是够,不够的话让她失败,没有货物

然后就用session获取用户,我直接定义了一个名字,然后实例化,实例化之后用lpush存贮值,判断一下就可以了

<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Loader;
use think\Request;

class Red extends Controller{
    public function red(){
        $arr=Db::table('kec')->select();
        $data=$this->fetch('red',['arr'=>$arr]);
        print_r($data);
    }
    public function ms(){
        $id=$_GET['id'];
        $sql=Db::table('kec')->find($id);
        if($sql['kc_num']<1){
            $this->error('没有货物');
        }
        $name='张三';
        $redis=new \Redis();
        $redis->pconnect('127.0.0.1','6379');
        $ms=$redis->lPush('ms',$name);
        if($ms){
            $this->success('秒杀成功');
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_42780341/article/details/86077092