reids配合PHP创建队列

使用redis创建一个队列

创建一个Queue类,使其拥有push,pop,getSize属性。符合队列的先进先出原则

client = new Client();
        $this->queueName = $queueName;
        $this->queueKey = "queue:".$queueName;
        $this->timeout = 0;
    }

    public function getSize()
    {
        return $this->client->llen($this->queueKey);
    }

    public function push($element)
    {
        $this->client->lpush($this->queueKey,$element);
    }

    public function pop()
    {
        return $this->client->brpop([$this->queueKey],$this->timeout);
    }

}

你可能感兴趣的:(reids配合PHP创建队列)