Skip to content

Releases: predis/predis

Predis v0.7.0

16 Jul 10:01
@nrk nrk
Compare
Choose a tag to compare

Predis is a flexible and feature-complete PHP client library for Redis.

This is a major release and it is not backwards compatible with the 0.6 series. Predis requires at least PHP 5.3.2 and works perfectly fine on PHP 5.4-dev. Support for PHP 5.2 has been irrevocably dropped and there will not be any more backported release. What follows is an overview of the new features and changes introduced with this new release. For a more in-depth list of changes please read the CHANGELOG.

New features and changes

PSR-0 autoloading

Predis now adheres to the PSR-0 standard that defines a precise scheme for autoloading widely accepted and used by more and more frameworks and libraries. This means that the times when the library consisted of a mere single file are now gone and you need to use a PSR-0 compatible autoloader to be able to use Predis. Basically any modern framework offers such a facility, but when you are using Predis in simple scripts you can just leverage the default basic autoloader class that comes with Predis by requiring Predis/Autoloader.php followed by Predis\Autoloader::register().

Packagist and Composer

Predis is available on Packagist making the library installable using Composer. This makes things a lot easier when managing dependencies in your applications and libraries. It is still possible to install Predis via PEAR using PearHub's channel.

Support for Redis versions and features

The default server profile is 2.4 which is currently the stable branch of Redis. The dev profile targets Redis 2.6 and supports some new features added to Redis such as server-side scripting with Lua. Support for Redis 1.0 has been completely removed.

Multiple connection backends

The default class responsible for connection and protocol handling is now part of a pluggable system that makes it possible to replace the default implementation with custom ones. For example, it is now possible to leverage the phpiredis C extension to lower the overhead of protocol handling thus gaining speed especially with multibulk replies.

$parameters = 'tcp://127.0.0.1:6379';
$options = array('connections' => array(
    'tcp'  => 'Predis\Network\PhpiredisConnection',
    'unix' => 'Predis\Network\PhpiredisConnection',
));

$client = new Predis\Client($parameters, $options);

This also opens up the possibility of having different classes implementing new kinds of protocols. Now that the redis scheme has been removed in favour of the tcp scheme, you can restore it with the following lines of code:

$parameters = 'redis://127.0.0.1:6379';
$options = array('connections' => array(
    'redis'  => 'Predis\Network\StreamConnection',
));

$client = new Predis\Client($parameters, $options);

Webdis

By leveraging the multiple-backends design for connections, Predis is able to talk with Webdis by default, albeit with certain restrictions since pipelining and transactions are not supported, provided that you are using a PHP interpreter with both the curl and phpiredis extensions loaded. Simply specify the http scheme in your connection parameters and use the client as you would normally do:

$client = new Predis\Client('http://127.0.0.1:7369');

Transparent key prefixing

Predis can now apply a prefix to your keys automatically by specifying a string in the prefix client option. The prefix is applied globally to your client instance which means that it will be used for all the connections that compose a cluster. The standard prefixing strategy is also able to handle commands with a complex use of keys such as SORT.

$client = new Predis\Client('tcp://127.0.0.1:6370', array('prefix' => 'pfx:'));

Future development

Predis v0.7.0 is actually very stable and it is already being used by many developers since a few months without any major issue reported, and recently a whole new comprehensive test suite has been added to ensure this stability. This is also a long overdue release that has been postponed many times in the past for various reasons, but all in all Predis v0.6 served well its purpose (no bugs reported for it since the release of v0.6.6 in April!) so now we can finally have a solid new major release.

There is one missing feature that was initially planned for Predis v0.7.0 but has now been postponed to Predis v0.8: support for redis-cluster. The release plans for redis-cluster changed quite a bit in the last months and it has been pushed back to later dates at least a couple of times. Add to that the fact that this shiny new beast would require some more changes in the internal design of Predis to provide a decent support and you will easily understand the reason for this decision.

Additional notes

Downloads

Related projects

Useful links

Predis v0.6.6

16 Jul 09:55
@nrk nrk
Compare
Choose a tag to compare

Predis is a flexible and feature-complete PHP client library for Redis. This is a maintenance release for the 0.6 series that features mainly performance improvements and adds some new features. 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 please see the CHANGELOG.

Please read also the roadmap for future releases paragraph.

New features and changes

New default server profile

The default server profile has been upgraded to Redis 2.2 since there are no changes that would break backwards compatibility in your applications. That said, if you are still using Redis 2.0 (or an older version of Redis) but you want to upgrade Predis, it is advisable to set accordingly the server profile that will be used by the client instance.

Long aliases for Redis commands are no more supported by default, but if you need them you can still require Predis_Compatibility.php which will automatically register new server profiles providing them.

Performance improvements

Performances for this release have been further improved resulting in an average 16% faster processing of multi bulk replies and a bit more throughput for pipelined and non-pipelined commands executed against local Redis instances.

A new lightweight response reader that uses less memory and is a bit faster than the previous one is now being used internally but the old handler-based response reader can be enabled by passing composable as the value for the new reader client option:

$client = new Predis\Client($server, array('reader' => 'composable'));

This option can also accept any class implementing the Predis\IResponseReader interface (e.g. Predis\FastResponseReader), which means that developers can create their own response readers.

A few core classes have also been optimized in order to generate less overhead when creating their instances.

UNIX domain sockets

Users can now connect to local Redis instances using UNIX domain sockets on POSIX systems:

$client = new Predis\Client('unix:///tmp/redis.sock');
$client = new Predis\Client(array('scheme' => 'unix', 'path' => '/tmp/redis.sock'));

Redis commands improvements

SINTERSTORE, SUNIONSTORE, SDIFFSTORE, ZINTERSTORE and ZUNIONSTORE can now accept an array to specify the list of the source keys to be used to populate the destination key:

$client->sinterstore('setOutput', array('setA', 'setB'));
$client->zunionstore('zsetOutput', array('zsetA', 'zsetB', 'zsetC'), $options);

The same applies for commands that simply accept a variable number of keys such as MGET, SINTER, SUNION, SDIFF, SUBSCRIBE and PSUBSCRIBE:

$keys = $client->mget(array('key1', 'key2', 'key3'));
$set = $client->sinter(array('setA', 'setB', 'setC'));
$client->subscribe(array('channel1', 'channel2', 'channel3'));

Notes

Roadmap for future releases (Predis v0.7.0)

Predis 0.7 has been in the works for a while now and the first stable release has been delayed a couple of times, but for very good reasons. Right now it is in a kind of beta stage but it is already being leveraged by a few developers in the wild with success. To cite a few points that will make it an exciting major release:

  • It targets only PHP >= 5.3. If you are still on PHP 5.2 then you will have to stick with Predis 0.6, but you should seriously consider to upgrade since PHP 5.2 is slower and it is not even supported anymore.
  • It is faster and consumes less memory than Predis v0.6.6 by default, with options to make it even faster.
  • The internal API is much more clean and coherent, and almost every class used internally by the library can be easily swapped by custom implementations. Almost nothing has changed in the way Redis commands are exposed by the main client class (using them is as easy as it has always been).
  • It complies with PSR-0 to play nice with many recent PHP frameworks such as Symfony2 (see also the excellent RedisBundle project).
  • It will transparently support Redis cluster (when available) as an option to the current cluster implemented via client-side sharding.

You should expect at least one more patch release for Predis 0.6 finalizing a couple of things before Predis v0.7.0 is officially released as stable.

Downloads

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

Useful links

Predis v0.6.5

16 Jul 09:54
@nrk nrk
Compare
Choose a tag to compare

Predis is a flexible and feature-complete PHP client library for Redis. This is a maintenance release for the 0.6 series exclusively aimed to fix a bug introduced in v0.6.4 when reading zero-length bulk replies from the server. For a complete list of the new features introduced in Predis v0.6.4 you can read the related release notes.

New features and changes

Fix for the zero-length bulk replies bug

Due to a minor change introduced in Predis v0.6.4 that was not covered by any test, zero-length bulk replies were being incorrectly handled, which resulted in protocol desynchronization errors. Here is a snippet to reproduce the issue with v0.6.4:

$redis->set('foo', '');
$foo1 = $redis->get('foo'); // correct value returned, but wrong protocol handling
$foo2 = $redis->get('foo'); // desynchronization error ensues with the successive read op.    

Notes

Credits

Thanks to Jordi Boggiano for quickly spotting the above-mentioned bug and providing a patch to fix the issue.

Downloads

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

Useful links

Predis v0.6.4

16 Jul 09:53
@nrk nrk
Compare
Choose a tag to compare

Predis is a flexible and feature-complete PHP client library for Redis. This is a maintenance release for the 0.6 series that features mainly performance improvements. 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 please see the CHANGELOG.

Please read also the roadmap for future releases paragraph.

New features and changes

Performance improvements

Various performance tweaks have been made for this release resulting in a faster reply parsing for big multi-bulk replies (that is, replies to commands that return list of elements such as LRANGE and KEYS) and more optimized code for client-side sharding. This is only a start since most of the speed / overhead improvements will be available starting from Predis 0.7.0, but the library is now 15% / 25% faster on average than previous versions in the above said scenario without any breaking changes to the public API.

MULTI / EXEC and automatic retries

Predis\MultiExecBlock now supports a new on_retry option accepting an external callback (any kind of callable object) that gets invoked whenever the server aborts a transaction and the client attempts to replay it.

$options = array(
    'watch' => array('foo'), 'cas' => true, 'retry' => 2, 
    'on_retry' => function($tx, $attemptsLeft) {
        echo "Number of attempts left: $attemptsLeft";
    },
);

$redis->multiExec($options, function($tx) {
    // Code for MULTI / EXEC transaction
});

PUBSUB automatic subscribption

Predis\PubSubContext can be initialized with the subscribe and psubscribe options to let the client transparently subscribe to the specified channels before entering the PubSub loop.

$subscriptions = array(
    'subscribe'  => array('control_channel', 'notifications'), 
    'psubscribe' => 'channel_*',
);

foreach ($redis->pubSubContext($subscriptions) as $message) {
    // PUBSUB loop
}

Notes

Roadmap for future releases

Predis 0.7.0 is currently in the works and it will be a major release with a whole lot of breaking changes (excepts for the Redis commands) and, for this very same reason, this is probably the right time to drop the backported version for PHP 5.2 and support only PHP >= 5.3. A lot of thoughts have been put into this decision and while such an online poll does not have statistical relevance given the low numbers, it shows an interesting tendency among developers that use Predis. If you add to that the fact that most of the recent frameworks are PHP 5.3-only and even the recently released Debian 6.0 Squeeze now ships with it, you should pretty much realize how PHP 5.3 is no more the future of PHP but its present. That said, those still relying on PHP 5.2 can continue using Predis 0.6: this version is very stable and feature complete and it is also very unlikely that Redis is going to add some new features soon that will require deep changes to the library to implement them. Basically, there is no pressing reason for you to upgrade. To ease this transition, Predis 0.6 will probably be officially maintained for a few months after the release of 0.7.

Downloads

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

Useful links

Predis v0.6.3

16 Jul 09:52
@nrk nrk
Compare
Choose a tag to compare

Predis is a flexible and feature-complete PHP client library for Redis. This is a maintenance release for the 0.6 series that features support for check and set (CAS) operations using the Predis\MultiExecBlock abstraction for MULTI/EXEC transactions and the addition of the remaining commands that will be part of Redis 2.2 (now in the RC stage). 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 please see the CHANGELOG.

New features and changes

Transactions with CAS support

With the addition of the WATCH command in Redis 2.2, it is now possible to use optimistic locking on keys to provide check and set operations. The abstraction for MULTI/EXEC implemented by the Predis\MultiExecBlock class now provides the ability to leverage this powerful concept by initializing a transaction with the CAS option set to true:

$options = array('cas' => true, 'watch' => 'foo');
$replies = $redis->multiExec($options, function($tx) {
    $foo = $tx->get('foo');
    // when cas => true, we *must* explicitly call MULTI
    $tx->multi();
    $tx->set('foobar', "atomic $foo!");
    $tx->mget('foo', 'foobar');
});

In case another client modified one of the WATCHed keys causing the current transaction to be aborted by the server, by default the client throws a Predis\AbortedMultiExec exception. By using the retry option, it is possible to instruct the client to transparently retry a certain number of times before giving up and throwing an exception:

$options = array('retry' => 2, 'cas' => true, 'watch' => 'foo');
$replies = $redis->multiExec($options, function($tx) {
    // attempts to execute this block for 3 times before giving up
});

It should be noted that developers can use the new CAS mode when writing code using the fluent interface API, with the only difference that the automatic retry mechanism for aborted transaction is not available (which means developers must roll their own solution):

$tx  = $redis->multiExec(array('watch' => 'foo', 'cas' => true));
$foo = $tx->get('foo');
$replies = $tx->multi()
              ->set('foobar', "atomic $foo!")
              ->mget('foo', 'foobar')
              ->exec();

New commands for Redis v2.2

All of the commands added in Redis v2.2 are now available with this release using the dev profile. Here is a list of the new commands added since Predis v0.6.2:

Notes

Downloads

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

Useful links

Predis v0.6.2

16 Jul 09:50
@nrk nrk
Compare
Choose a tag to compare

Predis is a flexible and feature-complete PHP client library for Redis. This is a maintenance release for the 0.6 series that mainly features internal optimizations, a more stable support for transactions (MULTI/EXEC) and comes with a bunch of new commands for Redis 2.2-dev. 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 please see the CHANGELOG.

New features and changes

Miscellaneous

Support MULTI/EXEC has been internally improved to handle a few corner cases with client-side exceptions and aborted transaction.

Aside from a bunch of new commands added for Redis 2.2 (STRLEN, LINSERT, RPUSHX, LPUSHX, ZREVRANGEBYSCORE, PERSIST) and a couple of fixes for SORT, now WATCH can be also called with an array of keys:

$redis->watch(array('foo', 'bar'));

Method chaining with UNWATCH and DISCARD using Predis\MultiExecBlock has been fixed and now it is possible to do:

$replies = $redis->multiExec(array('watch' => 'foo'))
                 ->set('foo', 'bar')
                 ->unwatch()
                 ->discard()
                 ->set('foo', 'bar')
                 ->execute();

Notes

Downloads

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

Useful links

Predis v0.6.1

16 Jul 09:48
@nrk nrk
Compare
Choose a tag to compare

Predis is a flexible and feature-complete PHP client library for Redis. This is a maintenance release for the 0.6 series featuring some internal optimizations and a more stable and consistent support for pipelines and transactions (MULTI/EXEC) without any breaking changes. 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 please see the CHANGELOG.

New features and changes

Transactions (MULTI/EXEC)

Support for dynamic arguments has been added to the Predis\Client::multiExec() method which can also accept an optional array of parameters to initialize the underlying transaction. Moreover, support for the WATCH and UNWATCH commands has been added when using the current development profile (Redis v2.2):

$transaction = $redis->multiExec();
$transaction->watch('foo')->get('foo')->unwatch('foo')->execute();

// or ...

$options = array('watch' => 'foo');
$transaction = $redis->multiExec($options, function($transaction) {
    $transaction->get('foo');
    $transaction->unwatch('foo');
});

See the WATCH and UNWATCH commands in the command reference of Redis for more details.

Command pipelines

Despite having been introduced with 0.6.0, the Predis\Client::pipelineSafe() method has been already deprecated (and might be removed in the next major release) in favour of the usual Predis\Client::pipeline() method with added support for dynamic arguments and an optional array of parameters used to initialize the underlying pipeline. The following lines of code are equivalent:

// the old way, deprecated but still valid for compatibility
$redis->pipelineSafe(function($pipe) { 
    // ... 
});

// the new way
$redis->pipeline(array('safe' => true), function($pipe) { 
    // ... 
});

// get a pipeline object instead of passing a callable
$pipe = $redis->pipeline(array('safe' => true));

Miscellaneous

Predis\MultiExecBlock and Predis\PubSubContext now throw an exception when trying to use features that depend on commands not supported by the server profile that is being used for the client:

$profile = '2.0';    // Redis 2.0 does not support WATCH and UNWATCH
$redis = new Predis\Client('redis://127.0.0.1/', '2.0');
$transaction = $redis->multiExec();
$transaction->watch("foo");    // throws a Predis\ClientException

An exception is also raised when trying to initialize Predis\MultiExecBlock and Predis\PubSubContext using a client connected to a cluster of servers since both work only on single connections.

Optional modifiers for ZRANGE, ZREVRANGE and ZRANGEBYSCORE can now be passed as an associative array to their respective methods. Also, ZRANGEBYSCORE now support the LIMIT modifier:

$redis->zrangebyscore('zsetkey', 1, 100, array(
    'limit'      => array('offset' => 1, 'count' => 2),  // or simply array(1, 2)
    'withscores' => true,
));

Notes

Downloads

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

Useful links

Predis v0.6.0

16 Jul 09:47
@nrk nrk
Compare
Choose a tag to compare

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