equip/redis-queue

This package is abandoned and no longer maintained. No replacement package was suggested.

Small library for using Redis as a job queue

0.1.0 2016-01-08 21:23 UTC

This package is auto-updated.

Last update: 2021-07-31 01:37:29 UTC


README

Latest Stable Version License Build Status Code Coverage Scrutinizer Code Quality

A small library for using Redis as a job queue in Equip applications.

Installation

Use Composer.

composer require equip/redis-queue

Add the DefaultConfigurationSet configuration to your project.

Consuming

Consumers are written as commands using equip/command. See its documentation for more information.

To run consumers, use a runner like the example included in this repository. This runner uses two environmental variables, REDIS_HOST and REDIS_PORT, to point to the Redis server to use; they default to '127.0.0.1' and 6379, respectively. The runner takes a single required parameter: the Redis key representing the queue from which the consumer is to retrieve jobs.

REDIS_HOST=example.com REDIS_PORT=12345 ./bin/consume queue_name

Note that your runner will need to configure your Auryn Injector instance appropriately for it to be able to create instances of your consumer command classes and their dependencies.

Publishing

Jobs are published using an instance of the Publisher class. Configuration included in DefaultConfigurationSet should be sufficient to have Auryn generate an instance of it.

Here's an example of publishing a job from a domain class, where Acme\Command\FooCommand is a command class intended to function as a consumer.

namespace Acme;

use Acme\Command\FooCommand;
use Equip\Adr\DomainInterface;
use Equip\RedisQueue\Publisher;

class FooDomain implements DomainInterface
{
	private $publisher;

    public function __construct(Publisher $publisher)
    {
        $this->publisher = $publisher;
    }

    public function __invoke(array $input)
    {
        // ...

        $command_options = ['foo' => 'bar'];
        $this->publisher->publish(
            'queue_name',
            FooCommand::class,
            $command_options
        );
    }
}

To publish a job, the publish() method of the Publisher instance is invoked with these arguments:

  • The first argument is a string containing the name of the queue, which must be a valid Redis key
  • The second argument is a string containing the fully-qualified name of a command class containing the logic for the job to execute
  • The third argument is an associative array of options to be used by an instance of the command class