github predis/predis v0.8.1
Predis v0.8.1

latest releases: v3.0.0-alpha1, v2.2.2, v2.2.1...
9 years ago

Predis is a flexible and feature-complete PHP (>= 5.3.2) client library for Redis.

This is a maintenance release for the 0.8 series. What follows is an overview of the new features and fixes introduced in this new release, for a more in-depth list of changes please see the CHANGELOG.

New features and changes

Client options

When using callables with client options accepting them, Predis now passes the current option instance as their second argument making it possible to get the default value for that option:

<?php
$options = array(
    'profile'  => function ($options, $option) {
        $profile = $option->getDefault($options);
        $profile->defineCommand('test', 'My\Command\TestCommand');

        return $profile;
    },
);

$client = new Predis\Client('tcp://127.0.0.1', $options);

Now you can use a callable with the connections option to initialize the instance of Predis\Connection\ConnectionFactoryInterface that will be used internally by the client to create the underlying connection:

<?php
$options = array(
    'connections' => function ($options, $option) {
        $factory = $option->getDefault($options);

        if (extension_loaded('phpiredis')) {
            $factory->define('tcp', 'Predis\Connection\PhpiredisConnection');
            $factory->define('unix', 'Predis\Connection\PhpiredisConnection');
        }

        return $factory.
    },
);

Client-side sharding based on node alias

There was this long-standing feature request that never got a decent solution shipped within the library in order to support named connections (distribution of nodes is based on their alias instead of the host:port pair), but now we have a generalized way to do that supported by both Predis\Cluster\Distribution\HashRing and Predis\Cluster\Distribution\KetamaPureRing and consists of passing a callable to the second argument of their constructors:

<?php
use Predis\Cluster\Distribution\HashRing;
use Predis\Connection\PredisCluster;

$options = array(
    'cluster' => function ($options) {
        $replicas = HashRing::DEFAULT_REPLICAS;

        $nodehash = function ($connection) {
            return $connection->getParameters()->alias;
        }

        $hashring = new HashRing($replicas, $nodehash);
        $cluster  = new PredisCluster($hashring);

        return $cluster;
    },
);

As you can see you can decide which kind of value to return from your callback, but keep in mind that everything will be casted to string by our hashring implementation.

Fix for edge case in Lua scripting abstraction

When leveraging the scripted commands abstraction Predis always tries to optimize things by using EVALSHA which, on the other hand, could fail with a -NOSCRIPT error if the Lua script referred by its SHA1 hash has not been cached by Redis yet. In these cases Predis automatically retries by issuing an EVAL command with the same arguments in addition to the whole Lua script body, but due to this bug the client wasn't using the original parseResponse() method from the initial command instance to parse the response.

Documentation

Thanks to dominics' initial push we have finally started with the long-overdue task of documenting Predis using Sphinx. Documentation is being written and integrated into our separate documentation branch, so make sure to open your pull requests against this branch if you plan to contribute.

Phpiredis extension

Thanks to the work of seppo0010 we were able to add the support for a PHP extension to parse the Redis protocol in a more efficient way since Predis v0.7.0, but now that the ownership of the phpiredis repository has been transferred to me I plan to tweak it and add new features from time to time (though the idea is to keep it minimal and simple). Having said that, I am by no means a C developer so help and contributions will be highly welcome and appreciated!

Additional notes

Downloads

Useful links

Don't miss a new predis release

NewReleases is sending notifications on new releases.