Home >Backend Development >PHP Tutorial >PHP 使用 Redis 回做队列服务

PHP 使用 Redis 回做队列服务

WBOY
WBOYOriginal
2016-06-13 12:18:46932browse

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 可以保证这一点。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn