redis簡易同時処理


$redis = new \Redis();
$redis->connect('127.0.0.1',6379);
$password = '123456';
$redis->auth($password);
$mobile='1500000000'.rand(0,9);
$number=10;          //  
$length=$redis->lLen("mobile");
if($length<=$number){
    $list_phone=$redis->lgetrange("mobile",0,-1);
    if(!in_array($mobile,$list_phone)){
        $redis->rpush("mobile",$mobile);
        //    
       $count= Db::name('user')->where('tel',$mobile)->count();
       if(!$count){
           Db::name('user')->insert(['tel'=>$mobile]);
       }
    }
}else{
    $redis->lpop('mobile');
}