php使用redis实现消息推送

用redis做队列,为了缓解瞬间请求服务器的压力。实际开发当中可通过定时任务去做。当然缺点是不够实时。

1.添加一个php文件,PushQueue.php

<?php

$redis=new redis();

$redis->connect('127.0.0.1','6379');

$arr=array(1,2,3,4,5,6,7);

foreach($arr $key=>$value)

{

  $redis->lpush('mylist',$value);//redis的list集合

}

 

2.添加另一文件,出队列。PopQueue

//多次执行这个文件,每次会出现一个值。

<?php

$redis=new redis();

$redis->connect('127.0.0.1','6379');

echo $redis->rpop('mylist');

 

来源:https://www.cnblogs.com/bush/p/6743616.html

posted @ 2018-11-21 10:47  aij_ling  阅读(1168)  评论(0)    收藏  举报