php+redis实现消息队列

2018-11-09T21:27:00

入队列

<?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
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »