Download the PHP package altmetric/reliable-queue without Composer
On this page you can find all versions of the php package altmetric/reliable-queue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download altmetric/reliable-queue
More information about altmetric/reliable-queue
Files in altmetric/reliable-queue
Package reliable-queue
Short Description A library for reliable queueing with Redis
License MIT
Informations about the package reliable-queue
Reliable Queue
A PHP library for reliable queueing backed by Redis.
Current version: 0.4.0
Supported PHP versions: 5.3, 5.4, 5.5, 5.6, 7
Installation
Usage
API Documentation
public ReliableQueue::__construct(string $name, string $queue, Redis $redis, LoggerInterface $logger)
Instantiate a new reliable queue object with the following arguments:
$name
: a uniquestring
name for this worker so that we can pick up any unfinished work in the event of a crash;$queue
: thestring
key of the list in Redis to use as the queue;$redis
: aRedis
client object for communication with Redis;$logger
: aPsr\Log\LoggerInterface
-compliant logger.
The returned object implements both the
Iterator
(and therefore
Traversable
) and
ArrayAccess
interface in
PHP.
This means that it can be iterated over with foreach
, yielding the queue name
and a value on every iteration. Internally, the library will block for new work
but this is invisible from a client's perspective.
You can also modify the queue as if it were an array by using the typical array operations:
public ChunkedReliableQueue::__construct(string $name, int $size, string $queue, Redis $redis, LoggerInterface $logger)
Instantiate a new chunked, reliable queue object with the following arguments:
$name
: a uniquestring
name for this worker so that we can pick up any unfinished work in the event of a crash;$size
: an integer maximum size of chunk to return on each iteration;$queue
: thestring
key of the list in Redis to use as the queue;$redis
: aRedis
client object for communication with Redis;$logger
: aPsr\Log\LoggerInterface
-compliant logger.
The returned object implements the
Iterator
(and therefore
Traversable
) interface in
PHP.
This means that it can be iterated over with foreach
, yielding the queue name
and an array of up to $size
elements on every iteration. Internally, the
library will block for new work but this is invisible from a client's
perspective.
If the queue contains sufficient items, the chunk of work will contain at most
$size
elements but if there is not enough work, it may return less (but
always at least 1 value).
public PriorityReliableQueue:__construct(string $name, array $queues, Redis $redis, LoggerInterface $logger)
Instantiate a new priority-ordered, reliable queue object with the following arguments:
$name
: a uniquestring
name for this worker so that we can pick up any unfinished work in the event of a crash;$queues
: anarray
ofstring
keys of lists in Redis to use as queues given in priority order;$redis
: aRedis
client object for communication with Redis;$logger
: aPsr\Log\LoggerInterface
-compliant logger.
The returned object implements the
Iterator
(and therefore
Traversable
) interface in
PHP.
This means that it can be iterated over with foreach
, yielding the queue name
and a value on every iteration. Queues will be checked randomly for work based
on their priority order given in $queues
meaning that the first queue will be
checked more often than the second, the second more than the third and so on.
Internally, the library will repeatedly poll for new work but this is invisible
from a client's perspective.
References
Acknowledgements
- Thanks to James Adam for suggesting a way to test the randomness of the priority queue.
License
Copyright © 2016-2017 Altmetric LLP
Distributed under the MIT License.