Skip to content
This repository

Predis 0.6.0 (2010-05-24) - Release notes

Predis is a flexible and feature-complete PHP client library for Redis. This release provides developers an even more stable, customizable and up-to-date client than previous versions, with just a tiny bit of overhead added when compared to the 0.5.x series. As with previous releases, Predis is also available for PHP 5.2 with an officially supported backport (PHP >= 5.2.6). What follows is an overview of the new features introduced in this new release. For a more in-depth list of changes plese see the CHANGELOG.

New features and changes

Server profiles

Predis 0.6.0 is fully compatible with Redis 2.0 (which has reached the RC stages just a few days ago at the time of writing) and its command set. The default server profile is set to 2.0. Those who are using older versions of Redis should specify the correct server profile accordingly when instantiating a new client (highly recommended):

$redis = new Predis\Client('redis://127.0.0.1/', '1.2');

For compatibility reasons, the old way of specifying which server profile to use is still valid:

$profile = Predis\RedisServerProfile::get('1.2');
$redis = new Predis\Client('redis://127.0.0.1/', $profile);

Please note that default support for Redis 1.0 has been removed and it is now provided only when including Predis_Compatibility.php as follows:

require_once('lib/Predis.php');
require_once('lib/Predis_Compatibility.php');

$redis = new Predis\Client('redis://127.0.0.1/', '1.0');

In accordance with the latest recommendations, Predis now uses the so-called new protocol (every command is serialized as a multibulk request) when connecting to Redis >= 1.2. The server profile for Redis 1.0 still uses inline and bulk requests though.

Client options

Now the second argument for Predis\Client::__construct() accepts also an array of client-level options or an instance of Predis\ClientOptions.

$options = array(
    'profile'            => '2.0',
    'key_distribution'   => 'Predis\Distribution\HashRing',
    'throw_on_error'     => true,
    'iterable_multibulk' => false,
);

$redis = new Predis\Client('redis://127.0.0.1/', $options);
  • profile [default: 2.0]: specifies which server profile to use. Accepts a version string (e.g. 1.2, 2.0, default, dev) or an instance of a class that inherits from Predis\RedisServerProfile.
  • key_distribution [cluster only - default: Predis\Distribution\HashRing]: specifies which distribution strategy to use to distribute keys when connecting to a cluster of Redis servers. Accepts a full class name (as a string) or an instance of a class that implements the Predis\Distribution\IDistributionStrategy interface.
  • throw_on_error [default: true]: specifies if server errors throw exceptions or they are returned as instances of Predis\ResponseError. Accepts boolean values.
  • iterable_multibulk [default: false]: specifies if multibulk replies are returned as arrays or as iterator instances (the latter enables the client to stream replies down to application's code). Accepts boolean values.

Connection parameters

The following example shows the new connection parameters that are in addition to the ones previously supported.

$connection_parameters = array(
    'alias'                 => 'cache-a',
    'weight'                => 100,
    'connection_async'      => false,
    'connection_persistent' => false,
);

$redis = new Predis\Client($connection_parameters);
  • alias [cluster only - default: not set]: identifies each connection by providing a mnemonic alias. Accepts string values.
  • weight [cluster only - default: not set]: specifies a weight used to balance the distribution of keys asymmetrically across multiple servers. Accepts integer values.
  • connection_async [default: false]: specifies if connections to servers are estabilished in a non-blocking way (the client is not blocked while the underlying resource performs the actual connection). Accepts boolean values.
  • connection_persistent [default: false]: specifies if the underlying connection resource should be left open when a script ends its lifecycle. Accepts boolean values.

Command pipelines

Command pipelines now support method chaining.

$replies = $redis->pipeline()->set('key', 'value')->get('key')->execute();

The new method Predis\Client::pipelineSafe() initializes a command pipeline that does not throw exceptions on server, protocol or connection errors. Instead, the generated exceptions are returned as values in the replies array. This new approach is useful when pipelines are used in a clustered environment since it enables the client to continue processing commands even if one or more servers in the cluster generate an error or become unavailable.

Transactions (Redis 2.0)

Predis 0.5.x already provided Redis transaction blocks via Predis\Client::multiExec(). The current implementation now supports method chaining and the ability to discard the commands issued in a transaction (see the DISCARD command in the command reference of Redis).

Publish / Subscribe (Redis 2.0)

Predis 0.6.0 supports PUBSUB contexts via PHP iterators with the new method Predis\Client::pubSubContext(). See the following example for more details.

Miscellaneous

It is now possible to get a new client instance for a single connection of a cluster by passing its alias to the method Predis\Client::getClientFor(). The new client inherits the same options of the originator client.

$cluster = new Predis\Client(array(
    'redis://127.0.0.1:6379?alias=first', 
    'redis://127.0.0.1:6379?alias=second'
));

$first = $cluster->getClientFor('first');
$first->info();

The Predis\RedisServerProfile class now allows developers to register their own server profiles or override the default ones provided by Predis.

class MyCustomProfile extends Predis\RedisServerProfile {
    public function getVersion() { return '2.2'; }
    public function getSupportedCommands() {
        // Implementation here...
    }
}

Predis\RedisServerProfile::registerProfile('MyCustomProfile', 'custom');
$redis = new Predis\Client('redis://127.0.0.1/', 'custom');

Notes

Roadmap for future releases

Since this new version of Predis already offers a multitude of new features and enhancements, the next releases in the 0.6.x series should contain only bug fixes, performance improvements and minor changes or additions. All the big new features will be reserved to the 0.7.x series, whose development cycle will be heavily influenced by the development cycle of Redis. Depending on the work needed to support future releases of Redis, 0.7.x might introduce some breaking changes. Long aliases for commands (e.g. $redis->setMultiple(), $redis->getMultiple() and such) are discouraged and should be considered obsolete as they could be removed in future major releases of Predis, depending on the feedback from the community.

Credits

I would like to especially thank Lorenzo Castelli for providing a whole lot of suggestions and reference code that hugely contributed to the final implementation of many new features shipped in this new version of Predis (see partial failures in pipelines, asynchronous connects, persistent connections, improvements in the current hashring implementation and a few minor fixes).

Thanks also to those who have reported bugs on the issue tracker and, finally, to all those who have sent me emails with words of appreciation for the work that has been made in Predis: these words are shared with anyone who contributed to make this new release possible.

Downloads

  • PHP 5.3 (mainline): TGZ or ZIP
  • PHP 5.2 (backport): TGZ or ZIP

Useful links

Something went wrong with that request. Please try again.