php+redis实现消息队列
入队列
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$password = '123456';
$redis->auth($password);
$arr = array('h','e','l','l','o','w','o','r','l','d');
foreach($arr as $k=>$v){
$redis->rpush("mylist",$v);
}
出队列
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$password = '123456';
$redis->auth($password);
//list类型出队操作
$value = $redis->lpop('mylist');
if($value){
echo "出队的值".$value;
}else{
echo "出队完成";
}
?>
建立定时任务
*/1 * * * * root php /wwwroot/workplace/redis/index.php
*/3 * * * * root php /wwwroot/workplace/redis/demo.php