2017 © Pedro Peláez
 

library redismq

Implementation of Pattern 'Reliable queue', using php and Redis

image

slaszu/redismq

Implementation of Pattern 'Reliable queue', using php and Redis

  • Tuesday, September 19, 2017
  • by slaszu
  • Repository
  • 1 Watchers
  • 1 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 50 % Grown

The README.md

Implementation of Pattern "Reliable queue", task queue using php and Redis

The idea is taken from Redis Documentation, (*1)

Install by composer

composer require slaszu/redismq

Important

All examples you can find in tests/UsecaseTest.php, (*2)

Configuration

This library use Predis to connect to Redis server. So we need predis object in examples below, (*3)

$this->client = new \Predis\Client([
    'scheme' => 'tcp',
    'host' => REDIS_SERVER_HOST,
    'port' => REDIS_SERVER_PORT,
]);

Create a queue

$queue = new \RedisMq\Queue($this->client, $name);

Add task (message) to queue

// 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);

Play with tasks

Get list of tasks to process

$taskQty = 100;
$taskList = $queue->getTaskList($taskQty);

Get task detail

$task = $taskList->getTask();
$message = $task->getMessage();
$body = $messageArray->getBody();

//variable $body is an array given in section "Add task (message) to queue"

Confirm task

$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., (*4)

Repair queue

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., (*5)

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., (*6)

Important: if all Tasks from TaskList are confirmed, then this TaskList is empty and Redis remove this task immediately., (*7)

$queue = new \RedisMq\Queue($this->client, $name);
$queue->repairTaskLists(60); // 60 is time in seconds

The Versions

19/09 2017

dev-master

9999999-dev

Implementation of Pattern 'Reliable queue', using php and Redis

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

22/06 2016

1.1.1

1.1.1.0

Implementation of Pattern 'Reliable queue', using php and Redis

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

22/06 2016

1.1.0

1.1.0.0

Implementation of Pattern 'Reliable queue', using php and Redis

  Sources   Download

The Requires

  • php >=5.4

 

The Development Requires

29/02 2016

1.0.1

1.0.1.0

RedisMQ implemented in PHP

  Sources   Download

The Development Requires

29/02 2016

1.0.0

1.0.0.0

  Sources   Download

The Development Requires