PHPackages                             mle86/wq-redis - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mle86/wq-redis

ActiveLibrary

mle86/wq-redis
==============

A Redis module for mle86/wq using the phpredis extension

v1.0.2(7y ago)02MITPHPPHP &gt;=7.1

Since Sep 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/mle86/php-wq-redis)[ Packagist](https://packagist.org/packages/mle86/wq-redis)[ RSS](/packages/mle86-wq-redis/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (8)Used By (0)

WQ-Redis (`mle86/wq-redis`)
===========================

[](#wq-redis--mle86wq-redis)

This package contains the PHP class `mle86\WQ\WorkServerAdapter\RedisWorkServer`.

It supplements the [**mle86/wq**](https://github.com/mle86/php-wq) package by implementing its `WorkServerAdapter` interface.

It connects to a [Redis](https://redis.io/) server using the [phpredis](https://pecl.php.net/package/redis) extension.

Version and Compatibility
=========================

[](#version-and-compatibility)

This is **version 1.0.2**of `mle86/wq-redis`.

It was developed for version 1.0.0 of `mle86/wq`and should be compatible with all of its future 1.x versions as well.

Installation and Dependencies
=============================

[](#installation-and-dependencies)

```
$ sudo apt install php-redis  # to install the phpredis extension
$ composer require mle86/wq-redis

```

It depends on PHP 7.1, [mle86/wq](https://github.com/mle86/php-wq), and the [phpredis](https://pecl.php.net/package/redis) extension.

Class reference
===============

[](#class-reference)

(`class mle86\WQ\WorkServerAdapter\RedisWorkServer implements WorkServerAdapter`)

It connects to a Redis server.

Because Redis does not have delayed entries, reserved entries, or buried entries, this class uses several custom workarounds to emulate those features.

For every `$workQueue` used, this class will create multiple Redis keys:

- `_wq.$workQueue` (ready jobs – List)
- `_wq_delay.$workQueue` (delayed jobs – Ordered Set)
- `_wq_buried.$workQueue` (buried jobs – List)

The delaying mechanism was inspired by [this StackOverflow response](http://stackoverflow.com/a/15016319).

- `public function __construct (\Redis $serverConnection)`
    Takes an already-configured `Redis` instance to work with. Does not attempt to establish a connection itself – use the `connect()` factory method for that instead or do it with `Redis::connect()` prior to using this constructor.
- `public function connect ($host = "localhost", $port = 6379, $timeout = 0.0, $retry_interval = 0)`
    Factory method. This will create a new `Redis` instance by itself.
    See [`Redis::connect()`](https://github.com/phpredis/phpredis#connect-open) for the parameter descriptions.

Interface methods which are documented in the [`WorkServerAdapter`](https://github.com/mle86/php-wq/blob/master/doc/Ref_WorkServerAdapter_interface.md) interface:

- `public function storeJob (string $workQueue, Job $job, int $delay = 0)`
- `public function getNextQueueEntry ($workQueue, int $timeout = DEFAULT_TIMEOUT) : ?QueueEntry`
- `public function buryEntry (QueueEntry $entry)`
- `public function requeueEntry (QueueEntry $entry, int $delay, string $workQueue = null)`
- `public function deleteEntry (QueueEntry $entry)`

Usage example
=============

[](#usage-example)

```
