Predis v0.7.0
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
- SncRedisBundle for Symfony2.
- PredisServiceProvider for Silex.