[TOC] ## demo queue.php ``` $redis = new Redis(); $redis->connect('127.0.0.1','6379'); //echo $redis->ping(); //在其他地方获存入队列 $redis->rPush("mylist", json_encode(["php", "aaa"])); $redis->rPush("mylist", "python"); $redis->rPush("mylist", "go"); while(true){ //获取弹出一个 //判断长度大于10 个执行一次 $range = $redis->lRange('mylist', 0, -1); if(count($range)>=10){ foreach(range(0 , 10) as $v){ $res =$redis->lPop('mylist'); echo $res; } }else{ sleep(1); } } ``` client.php ``` sleep(2); $redis = new Redis(); $redis->connect('127.0.0.1','6379'); //在其他地方获存入队列 $redis->rPush("mylist", json_encode(["php", "aaa"])); $redis->rPush("mylist", "python"); $redis->rPush("mylist", "go"); $redis->rPush("mylist", "go"); $redis->rPush("mylist", "go"); $redis->rPush("mylist", "go"); $redis->rPush("mylist", "go"); $redis->rPush("mylist", "go"); ``` 运行 ``` $ php queue.php $ php client.php ```