Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 444d4bd0b0
Fetching contributors…

Cannot retrieve contributors at this time

102 lines (72 sloc) 4.613 kb


An asynchronous (non-blocking) version of Predis, the flexible and feature-complete PHP client library for the Redis key-value store, built on top of React and using phpiredis to benefit from parsing the Redis protocol from inside a PHP extension.

Predis\Async is currently highly experimental which means that it is unstable, lacks various features and the API is ugly and not yet finalized as of now. The client foundation is being built on top of the evented loop abstraction offered by React, a new event oriented framework for PHP under heavy-development that aims to provide everything needed to build reusable components and applications using an evented approach with non-blocking I/O.

I would like to stress the fact that the code in Predis\Async is addmittedly still ugly and blatant bugs are most likely right around the corner, but feel free to open pull-requests with fixes or just report them.

Contributions to both Predis\Async and React are highly welcome and appreciated.


Predis\Async is available on Packagist and can be installed through Composer. Using it to your application is simply a matter of adding "predis/predis-async": "dev-master" in your composer.json list of requireed libraries. Also remember that you must have phpiredis pre-installed as a PHP extension.


require __DIR__.'/../autoload.php';

use Predis\Async\Client as PredisAsync;
use React\EventLoop\StreamSelectLoop as EventLoop;

$listener = new PredisAsync('tcp://', $loop = new EventLoop());

$listener->connect(function () use ($listener) {
    echo "Connected to Redis, now listening for incoming messages...\n";

    $logger = new PredisAsync('tcp://', $listener->getEventLoop());

    $listener->subscribe('nrk:channel', function ($event) use ($logger) {
        list(, $chan, $msg) = $event;

        $logger->rpush("store:$chan", $msg, function () use ($chan, $msg) {
            echo "Stored message `$msg` from $chan.\n";


Differences with Predis

Being an asynchronous client implementation, the underlying design of Predis\Async is quite different from the one of Predis which is a blocking implementation. Certain features have not been implemented yet (or cannot be implemented at all), just to name a few you will not find the usual abstractions for command pipelines or MULTI/EXEC contexts and support for client-side sharding is still not there. That said, the two libraries share a few common classes making it possible, for example, to use different server profiles or define commands with their own arguments filter / reply parser.

Most immediate TODO list

  • Provide a better API that suits best the asynchronous model.
  • Add tests. Lots of them.
  • Everything else.


If you want to work on Predis\Async, it is highly recommended that you first run the test suite in order to check that everything is OK, and report strange behaviours or bugs. When modifying Predis please make sure that no warnings or notices are emitted by PHP by running the interpreter in your development environment with the error_reporting variable set to E_ALL | E_STRICT.

The recommended way to contribute to Predis\Async is to fork the project on GitHub, create new topic branches on your newly created repository to fix or add features (possibly with tests covering your modifications) and then open a new pull request with a description of the applied changes. Obviously you can use any other Git hosting provider of your preference.





The code for Predis\Async is distributed under the terms of the MIT license (see LICENSE).

Jump to Line
Something went wrong with that request. Please try again.