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.
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.
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));
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,
));