Save the request into redis
In order to simulate requests from multiple users, use a for loop instead
//redis数据入队操作$redis = new Redis();$redis->connect('127.0.0.1',6379);for($i=0;$i<50;$i++){try{$redis->lPush('test',rand(1000,9000)); }catch(Exception $e){echo $e->getMessage(); } }
# ##########################################Perform data processing in the background## ####Daemon###
//redis数据出队操作,从redis中将请求取出$redis = new Redis();$redis->pconnect('127.0.0.1',6379);while(true){try{$value = $redis->lPop('test');if(!$value){break; }//var_dump($value)."n";/* * 对$value进行逻辑和数据处理 */}catch(Exception $e){echo $e->getMessage(); } }
The above is the detailed content of How to handle redis queue in php. For more information, please follow other related articles on the PHP Chinese website!