The idea is taken from Redis Documentation
composer require slaszu/redismq
All examples you can find in tests/UsecaseTest.php
This library use Predis to connect to Redis server. So we need predis object in examples below
$this->client = new \Predis\Client([
'scheme' => 'tcp',
'host' => REDIS_SERVER_HOST,
'port' => REDIS_SERVER_PORT,
]);
$queue = new \RedisMq\Queue($this->client, $name);
// eg. this is message with array, but message could be a simple string either
$message = new \RedisMq\Message([
'x' => 2,
'string' => 'Message number 2',
'rand' => rand(10000, 99999)
]);
$queue->addMessage($message);
$taskQty = 100;
$taskList = $queue->getTaskList($taskQty);
$task = $taskList->getTask();
$message = $task->getMessage();
$body = $messageArray->getBody();
//variable $body is an array given in section "Add task (message) to queue"
$task = $taskList->getTask();
/*
* .....
* proccess message (task details) from task and if is all right then confirm this task
* .....
*/
$task->confirm();
Task is removed from queue after confirmation.
When you get TaskList from Queue, then Tasks are moved from Queue to TaskList. Task which are in TaskList not exist any longer in Queue.
In some situations you may want to move task from TaskList back to Queue. To do this use repairTaskLists method. This method takes one param (time in seconds). This is the minimum time that has elapsed since the creation of TaskLists. This method check all Task Lists that was created from Queue.
Important: if all Tasks from TaskList are confirmed, then this TaskList is empty and Redis remove this task immediately.
$queue = new \RedisMq\Queue($this->client, $name);
$queue->repairTaskLists(60); // 60 is time in seconds