php redis秒殺

php redis秒殺

   function get(){
        $random = rand(0,9);
        if($random !== 0){
            return $this->out("get fail");
        }
        $count = $this->redis->get("flag");
        if($count < 100000){
            $random = RandomKey::string(32);
            if(empty($count)){
                $count = 1;
                $this->redis->set("flag", $count);
            }
            if($this->redis->zAdd("goods", $count, $random)){
                $this->redis->incr("flag");
                return $this->out("good luck");
            }
        }
        else{
            return $this->out("finish");
        }
        return $this->out("get fail");
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章