码迷,mamicode.com
首页 > Web开发 > 详细

PHP 使用 Redis 来做队列服务

时间:2015-04-28 22:56:54      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:php 使用 redis 来做队列服务


<?php
 
class Queue
{
    protected $redis;
    protected $key;
 
    public function __construct(\Redis $redis, $key)
    {
        $this->redis = $redis;
        $this->key = $key;
    }
 
    public function pop()
    {
        return $this->redis->lPop($this->key); // 左边出
    }
 
    public function push($task)
    {
        return $this->redis->rPush($this->key, $task); // 右边入
    }
}

队列的一个特点就是先进先出(FIFO),很显然,先产生的任务需要被先处理,redis 的 List 可以保证这一点。

PHP 使用 Redis 来做队列服务

标签:php 使用 redis 来做队列服务

原文地址:http://blog.csdn.net/phpfenghuo/article/details/45342247

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!