队列先进先出,栈先进后出
在redis
中rpush
和lpop
经常一起使用
那么blpop
有什么作用?
Redis Blpop 命令移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。
<?php $redis = new redis();
$redis -> connect('127.0.0.1',6379);
$redis -> flushAll();
$redis -> lPush('favorite_fruit','apple');
while(1){
echo "sleep";
var_dump($redis -> blPop('favorite_fruit',10));
}
优点
节约服务器资源
通过redis和blpop
可以比较方便的实现近实时的计划任务
有任务推入到redis的队列中,然后blpop来消费,没有进行阻塞
比crontab每分钟执行高效很多
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:redis中列表阻塞弹出blpop 出自老鄢博客 | 欢迎分享