predis

A flexible and feature-complete Redis client for PHP.

MIT License

Downloads
223.4M
Stars
7.5K
Committers
101

Bot releases are hidden (Show)

predis - Predis v1.0.0

Published by nrk over 8 years ago

This is not only a new and major release of Predis, but it is an important milestone because it represents the first stable release in terms of API (both public and internal). Lots of changes have been made to improve the overall design and code quality while optimizing the library as much as possible.

You can consult the CHANGELOG for more details about changes and bug fixes introduced in this release.

IMPORTANT NOTE: we switched to PSR-4 for autoloading but PEAR packaging still uses PSR-0 for obvious reasons, the conversion is performed when generating the package using bin/create-pear. We do not plan to support installation through PEAR indefinitely, but we will stick with it for a few more releases.

Introduction

One of the purposes of this new release was to make use of better names for classes, interfaces and namespaces so we ended up with shorter fully-qualified names and a better organization of namespaces. While these changes can be quite radical in certain cases, the truth is that they will most likely affect only code-bases where developers made use of certain classes to extend the library with custom features. Those simply using Predis as a client will not probably notice any difference. Just to make a few examples (for the rest, see the CHANGELOG):

  • The Predis\Option namespace is now Predis\Configuration.
  • The Predis\Command\AbstractCommand class is now Predis\Command\Command.
  • The Predis\Command\ScriptedCommand class is now Predis\Command\ScriptCommand.
  • Aggregate connections (cluster, replication) are in the Predis\Connection\Aggregate namespace.
  • Classes representing status and error responses are in the Predis\Response namespace.

Obviously it is not only a matter of renaming or moving things around, the overall internal design of Predis has been dramatically improved and now certain aspects of the library (such as clustering) are more solid and more open to extension. Last but not least a lot of work has been done to keep performances in check, resulting in less overhead when initializing client instances and no difference at runtime in raw numbers compared to v0.8.x despite the additional flexibility.

Improvements

  • @method in docblocks: while this is not strictly a feature, now Predis ships with @method tags for Predis\ClientInterface and Predis\ClientContextInterface (pipelines, transactions) so you can leverage autocompletion and inspection while coding with your favourite IDE. This should be a much welcome addition for many developers since it has been requested many times in the last couple of years.

  • Server profiles: the default one is now 3.0 (obviously targeting Redis 3.0.0). It is safe to switch now since the are no breaking changes between Redis 2.8 and 3.0. At the same time, the server profile for Redis 1.2 has been removed since it is relatively ancient stuff.

  • New commands: added SENTINEL to the server profile for Redis 2.6 and PUBSUB to the server profile for Redis 2.8. Please note that you will not find CLUSTER and other commands used by redis-cluster in the server profile for Redis 3.0. Internally they are used as raw commands, they may be added in the future though as soon as Redis 3.0 becomes stable.

  • Raw commands: now they can be sent simply by providing an array of arguments (comprising of the command ID) to Predis\Client::executeRaw(). This method skips key prefixing (and more generally, any command processor) and response parsing, so it always returns responses as documented on the Redis website. It is also possible to tell when Redis returns an error thanks to the second optional argument populated by reference with a boolean value:

    $response = $client->executeRaw(["SET", "foo", "bar"]); // string(2) "OK"
    $response = $client->executeRaw(["STRLEN", "foo"]);     // int(3)
    
    // When $iserror is TRUE, $response contains the error string.
    $response = $client->executeRaw(["LPUSH", "foo", "bar"], &$iserror);
    
  • Changes for ZRANGE-like commands using WITHSCORES: Predis used to return the member and score pair as an array of [$member, $score] when using the WITHSCORES modifier with ZRANGE, ZREVRANGE, ZRANGEBYSCORE and ZREVRANGEBYSCORE. Now the raw response is parsed to a named array so members and their scores can be accessed as $member => $score.

    $members = $client->zrange("key", 0, -1, "withscores");
    // Predis v0.8 (old): [["member1", "score1"], ...]
    // Predis v1.0 (new): ["member1" => "score1", ...]
    

    The output of ZSCAN has also been changed accordingly in order to reflect the same output, while Predis\Collection\Iterator\SortedSetKey is not affected by this change. NOTE: the ordering of the original response is still preserved thanks to how PHP internally works with named arrays.

  • Redis responses: status responses are now returned as instances of Predis\Response\Status and carry their original payload string. +OK is then no more returned to the client as a boolean TRUE, but since a status response can be transparently casted to string one can do $response == "OK" which is also more akin to how Redis replies to clients. Instances of common status responses such as +OK or +QUEUED are shared internally in order to avoid wasting memory. Another change regards custom response parsers in commands (see Predis\Command\CommandInterface::parseResponse()) which are now applied inside consumer classes such as Predis\Client.

  • Client options: the fully reworked Predis\Configuration\Options class now has the ability to lazily initialize values using objects that respond to __invoke() and it works even for custom options defined by the user. This is an example of a complex and modular set of options where standard and user-defined options are mixed together, and the ones regarding cluster are initialized lazily only when needed by the client:

    $client = new Predis\Client($parameters, [
      'exceptions'  => true,
      'connections' => [
        'tcp'  => 'Predis\Connection\PhpiredisStreamConnection',
      ],
      'distributor' => function () {
        return new Predis\Cluster\Distributor\KetamaRing();
      },
      'strategy'    => function ($options) {
        return new Predis\Cluster\PredisStrategy($options->distributor);
      },
      'cluster'     => function ($options) {
        $strategy = $options->strategy;
        $cluster = new Predis\Connection\Aggregate\PredisCluster($strategy);
    
        return $cluster;
      },
      'profile'     => function ($options, $option) {
        $profile = $options->getDefault($option);
        $profile->defineCommand("luascript", "Nrk\Command\LuaScriptCommand");
    
        return $profile;
      },
    ]);
    

    In addition to the client options already supported by v0.8, the new aggregate option overrides both cluster and replication and can be used to initialize an aggregate connection taking full control over its initialization (the return type must be Predis\Connection\AggregateConnectionInterface).

  • Cluster with client-side sharding: Predis now uses the same rules defined by the redis-cluster specification when dealing with empty hash-tags {} in keys, so upgrading Predis might affect the distribution of your already-deployed cluster. If you want to make sure that you will not be affected by this change, you can extend Predis\Cluster\PredisStrategy to override the extractKeyTag($key) method and configure the client to use your strategy like this:

    class OldPredisStrategy extends Predis\Cluster\PredisStrategy
    {
      protected function extractKeyTag($key)
      {
        if (false !== $start = strpos($key, '{')) {
          if (false !== $end = strpos($key, '}', $start)) {
            $key = substr($key, ++$start, $end - $start);
          }
        }
    
        return $key;
      }
    }
    
    $client = new Predis\Client($nodes, [
      "cluster" => function () {
        $strategy = new OldPredisStrategy();
        $cluster = new Predis\Connection\Aggregate\PredisCluster($strategy);
    
        return $cluster;
      },
    ]);
    

    This is possible because, starting with v1.0, Predis\Connection\Aggregate\PredisCluster accepts an instance of Predis\Cluster\StrategyInterface as the only argument in its constructor instead of Predis\Cluster\Distributor\DistributorInterface. The distributor, on the other hand, is now wrapped by Predis\Cluster\PredisStrategy.

  • Pipeline options: Predis\Client::pipeline() now accepts options to choose which kind of pipeline object should be initialized among the ones supported by Predis:

    • atomic: wraps the pipeline in a MULTI / EXEC transaction (Predis\Pipeline\Atomic).
    • fire-and-forget: does not read back responses (Predis\Pipeline\FireAndForget).
  • Transaction options: while Predis\Transaction\MultiExec still supports cas, watch and retry, there are also a couple of changes:

    • exceptions: overrides the value of $options->exceptions provided in client options.
    • on_retry: this option has been removed.
  • Key prefixing: while changes in this case are completely transparent to users, the prefixing logic has been moved from command classes to the key prefix processor returned by $options->prefix. Commands are recognized by their IDs and developers can define or override the handlers used to prefix keys based on their arguments. This makes it possible to prefix keys also when using the generic Predis\Command\RawCommand class.

Dropped stuff:

  • Obsolete methods: Predis\Client::multiExec() and Predis\Client::pubSub() have been removed after having been deprecated in v0.8.5. The new names for these methods are respectively Predis\Client::transaction() and Predis\Client::pubSubLoop().
  • Iterable multibulk responses: the commonly used Predis\Connection\StreamConnection does not support them anymore and iterable_multibulk has been removed from the default connection parameters. You can still use them with Predis\Connection\CompositeStreamConnection (it is slower, but makes use of a pluggable protocol system) and the classes implementing multibulk iterators are available in the Predis\Response\Iterator namespace.
  • Pipeline executors: they are no more needed after the changes in Predis\Pipeline\Pipeline.

What's next?

Having finally reached v1.0 is a great milestone considering that Predis has been around for 5 years now, but there is obviously more to come: v1.1 will ship with new features and the most important ones will most likely be support for redis-sentinel with replication and support for slaves in redis-cluster. Minor versions will be released more frequently compared to the past, now that the library is considered stable in terms of design and API.

There is also another aspect that should really be addressed: documentation. Predis simply does not have enough documentation covering useful features or the inner parts of the library. I plan to resume the initial efforts started in the documentation branch but frankly I hope to receive also some external contributions.

All in all I am happy with this release and even though it took 7 months to ship (way more than what I originally planned, mostly due to some busy months) the result is more than satisfactory in terms of quality. Big thanks to everyone who has shared their feedbacks or contributed with suggestions and code!

KTHXBYE.

Downloads

predis - Predis v1.0.4

Published by nrk over 8 years ago

This is a maintenance release for the 1.0 series. What follows is an overview of the changes and bug fixes introduced in this release, more details are available in the CHANGELOG.

IMPORTANT: Predis v1.1.0 is going to be released in just a few days, this minor release will ship with various improvements and the much-awaited support for redis-sentinel. Soon after that the master branch will host the development of Predis v2.0 and the first major change will be a bump of the minimum required version of PHP to 5.5.9, please read about it here and leave a comment if you have something to say on the matter as the decision has not been finalized as of yet.

Improvements

  • Added a new profile for Redis 3.2 with its new commands: HSTRLEN, BITFIELD, GEOADD, GEOHASH, GEOPOS, GEODIST, GEORADIUS, GEORADIUSBYMEMBER. The default server profile for Predis is still the one for Redis 3.0 so you must set the profile client option to 3.2 when initializing the client in order to be able to use them when connecting to Redis 3.2.
  • redis-cluster: when the connection to a specific node fails the client tries to connect to another node in order to refresh the slots map and perform a new attempt to execute a command.
  • redis-cluster: connections to nodes can now be preassigned to non-contiguous slot ranges via the slots parameter using a comma separator (e.g. tcp://127.0.0.1:6379?slots=0-5460,5500-5600,11000)

Bug fixes

  • FIX: Predis\Collection\Iterator\HashKey was returning corrupted values when iterating hash keys containing integer fields (PR #330, ISSUE #331).
  • FIX: Predis\Connection\StreamConnection and Predis\Protocol\Text\RequestSerializer do not fail when serializing commands with holes in their arguments (e.g. [0 => 'key:0', 2 => 'key:2']) just like the phpiredis-based connection backends (ISSUE #316).

Other links

predis - Predis v1.0.3

Published by nrk about 9 years ago

This is a maintenance release for the 1.0 series. What follows is an overview of the changes and bug fixes introduced in this release, more details are available in the CHANGELOG.

IMPORTANT NOTICE: this release supersedes v1.0.2.

Bug fixes

  • FIX: the previous release introduced a severe regression on HHVM preventing the client from connecting to Redis using IPv4 addresses. Code running on the standard PHP interpreter is unaffected. (#269)

Other links

predis - Predis v1.0.1

Published by nrk about 9 years ago

This is a maintenance release for the 1.0 series. What follows is an overview of the changes and bug fixes introduced in this release, more details are available in the CHANGELOG.

Improvements

  • Added the BITPOS command to the server profile for Redis 2.8 (pull request by @nicchap).
  • It is now possible to specify a timeout for read/write operations also when using UNIX domain sockets with Predis\Connection\StreamConnection which is the default connection class based on PHP's streams (pull request by @srhnsn).

Bug fixes

  • A bug prevented Predis\Collection\Iterator\SortedSetKey to work correctly when iterating over sorted sets containing integer members (see #216).
  • Applied a workaround for a bug in old versions of PHP < 5.3.9 affecting inheritance (see 99f4312a6feb2cadaf83b008d006c1720f580723).
  • Prevent E_NOTICE messages from being emitted when requesting empty or unexistent info sections using INFO.

Notes

  • Due to a bug in HHVM <= 3.4.0, it is not possible to use Predis\PubSub\Consumer and Predis\Monitor\Consumer when running under Facebook's runtime for now. You can find more details in the discussion on #231 (thanks @rubensayshi for the catch!) which also provides an hack to work around this issue until the next release of HHVM will ship with their bug fixed.

Downloads

predis - Predis v1.0.2

Published by nrk about 9 years ago

This is a maintenance release for the 1.0 series. What follows is an overview of the changes and bug fixes introduced in this release, more details are available in the CHANGELOG.

IMPORTANT NOTICE: this release has been superseded by v1.0.3 due to a severe regression affecting only HHVM preventing the client from connecting to Redis using IPv4 addresses. Code running on the standard PHP interpreter is unaffected.

Improvements

  • IPv6 is fully supported.
  • The redis scheme can be used in URI strings and is considered an alias of tcp but the rules applied when parsing the URI follow the provisional registration document published by IANA while the usual Predis-specific rules still apply when using tcp and other schemes.
  • Implemented some missing commands: HSTRLEN (Redis >= 3.2), ZREVRANGEBYLEX (Redis >= 2.8) and MIGRATE (>= 2.6).
  • The ZADD modifiers NX|XX, CH, INCR introduced in Redis 3.0.2 can also be used with the simplified signature of this command where scores and members are passed as a named array.

Bug fixes

  • FIX: Predis\Configuration\Options must not trigger the autoloader when values are strings (#257).
  • FIX: BITPOS was not defined in the key-prefix processor (#265) and in the replication strategy.

Notes

  • Predis v1.1.0 should follow in just a few weeks and, being a minor release, will deliver more than just bugfixes or minor improvements. The addition of support for redis-sentinel is a long-standing feature request that will hopefully find its way into the library (see #131) and some major and much needed improvements to redis-cluster are also scheduled (see #173). As usual any help is more than appreciated so feel free to hop on these issues for sharing ideas and advices, or even contribute with a pull request.

Other links

predis - Predis v0.8.7

Published by nrk about 10 years ago

This is a maintenance release for the 0.8 series. What follows is an overview of the changes and bug fixes introduced in this release, more details are available in the CHANGELOG.

New features

Redis commands

  • Added the profile alias 3.0 for Redis 3.0, but 2.8 is still the default one.
  • Added COMMAND to the server profile for Redis 2.8. This command is actually available since Redis 2.8.13 so it will return a -ERR when executed against older versions of Redis.

Redis Cluster

The new default for redis-cluster when the client receives a -MOVED response is to fetch an updated slots map automatically from the node target of the persistent redirection. Thanks to this change you can now feed the client constructor with only a few of the nodes in your cluster without the need to use a more complex configuration, so even if your cluster have - let's say - 10 nodes you can still use only a couple or more connection parameters:

$client = new Predis\Client(
    ["tcp://10.0.0.1:6379", "tcp://10.0.0.1:6380"],
    ["cluster" => "redis"]
);

Internally the client fetches the slots map using the new CLUSTER SLOTS command made available since Redis 3.0.0b7, which means your nodes must be upgraded to the most recent beta release of Redis (but you should do it anyway since it is beta software).

PubSub

Implemented PING in our PUB/SUB loop abstraction for Redis >= 3.0.0b8. You can now ping the connection with an optional payload directly from the loop instance, and receive back a PONG message:

foreach ($pubSubLoop as $message) {
    switch ($message->kind) {
        case "subscribe":
            $pubSubLoop->ping("hello!");
            break;

        case "pong":
            echo "Pong message with payload $message->payload\n";
            break;
    }
}

Bug fixes

  • The patch applied in v0.8.6 to fix #180 introduced a regression affecting read/write timeouts in Predis\Connection\PhpiredisStreamConnection so we had to apply a further fix which, unfortunately, absolutely requires PHP 5.4+ meaning that read/write timeouts will be ignored from now on PHP 5.3.

Downloads

predis - Predis v0.8.2

Published by nrk over 10 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

Fix for response parsing in pipelines

The main reason for this new patch release is to fix a bug introduced right before releasing v0.8.0 that prevented complex responses from Redis from being parsed correctly in command pipelines as reported on this issue. This bug didn't affect correctness of the data stored or returned by Redis, but prevented replies to certain commands such as HGETALL from being parsed by the client before returning to the user's code.

Predis-based session handler

A new class Predis\Session\SessionHandler has been added to provide an easy way to use Predis as a backend to store PHP's sessions on Redis. This new class is mainly intended for PHP >= 5.4 since it implements SessionHandlerInterface but it can be used with PHP 5.3 if a polyfill for this interface is provided by you or an external package in your dependencies (such as symfony/http-foundation just to name one).

<?php
$client = new Predis\Client('tcp://127.0.0.1', array('prefix' => 'sessions:'));
$handler = new Predis\Session\SessionHandler($client);
$handler->register();

See a more exhaustive example.

Predis service provider for Silex

Along with this release, the official service provider for Silex has been finally updated to use Predis v0.8 with a new version bump that brings some breaking changes when dealing with multiple clients configuration. These changes was necessary to better fit with the boot mechanism for service providers that was introduced a few months ago in Silex.

Additional notes

Downloads

Useful links

predis - Predis v0.8.3

Published by nrk over 10 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 shipping some new features and minor micro-optimizations. What follows is an overview of the new features and changes introduced in this new release, for a more in-depth list of changes please see the CHANGELOG.

New features and changes

CLIENT SETNAME and CLIENT GETNAME

Thanks to Raphael Stolt's pull request you can now use CLIENT SETNAME and CLIENT GETNAME.

New stream-based phpiredis connection backend

We've had a connection backend based on the phpiredis extension for quite some time now, but it required the socket extension to be loaded in order to work. Now there's a new connection backend which still relies on phpiredis to parse and serialize the Redis protocol, but internally uses PHP's native streams. One of the benefits of using streams is that they support persistent connections when used with plain FastCGI or php-fpm processes. Client configuration to make use of this connection backend is the same as usual, you just need to specify the Predis\Connection\PhpiredisStreamConnection class:

<?php
$client = new Predis\Client('tcp://127.0.0.1', array(
    'connections' => array(
        'tcp'  => 'Predis\Connection\PhpiredisStreamConnection',
        'unix' => 'Predis\Connection\PhpiredisStreamConnection',
    ),
);

TCP_NODELAY with stream-based connections (PHP >= 5.4.0 only)

One of the historic downsides of using stream-wrapped sockets has always been the impossibility of tinkering with socket options, but luckily for us the introduction of socket_import_stream() in PHP 5.4 removed this limitation. This make it possible to set the TCP_NODELAY socket option to enable or disable Nagle's algorithm using the tcp_nodelay connection parameter:

<?php
$client = new Predis\Client('tcp://127.0.0.1?tcp_nodelay=0');

You can effectively set any kind of socket option by yourself in your library or application's code with something like:

<?php
$client = new Predis\Client('tcp://127.0.0.1');
$socket = socket_import_stream($client->getConnection()->getResource());
socket_set_option($socket, SOL_TCP, TCP_NODELAY, 0);

Callable objects for$parameters in client constructor

Additionally to strings, arrays or even instances of Predis\Connection\ConnectionInterface, now the first argument of Predis\Client::__construct() can accept callable objects returning instances of Predis\Connection\ConnectionInterface. This may appear as an unnecessary addition, but it can reveal itself useful to create custom and self-contained solutions to handle complex configuration scenarios. As an (admittedly) extreme example, we relied on this feature to wrap the code needed to use client-side sharding to distribute keys among virtual nodes of replicated Redis instances without further changing the library's code.

Minor non-breaking change in Lua scripting abstraction

When instructing scripted commands to use all the arguments to populate the ARGV table and leave KEYS empty on Lua's side, developers were required to return FALSE (strictly boolean) from getKeysCount() in their command implementation. This choice didn't make much sense and now you can simply return 0. This change does not break existing code since 0 == FALSE in PHP.

Changes in redis-cluster distribution

Salvatore recently started working again on redis-cluster (that alone is an awesome news!) and commited a change raising the number of hash slots used for distribution, from 4096 to 16384. Our aggregated connection for redis-cluster has been updated accordingly, so pay attention when upgrading both Redis and Predis if you were brave enough having something based on it.

Additional notes

Downloads

Useful links

predis - Predis v0.8.1

Published by nrk over 10 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

predis - Predis v0.8.0

Published by nrk over 10 years ago

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

This is a major release and it is not backwards compatible with the v0.7.x series due to the fact that some namespaces and classes have been renamed or moved and a few parameters and client options have been modified. What follows is an overview of the new features and major changes introduced with this new release, for a more in-depth list of changes please read the CHANGELOG.

New features and changes

Support for Redis versions and features

The default server profile is now 2.6 which is the current stable branch of Redis while the dev profile targets Redis 2.8. Please note that starting with Redis 2.6 the output of INFO is splitted into sections and, to accomodate this change, Predis returns nested named arrays when using the 2.6 profile.

Connection parameters and client options

There are some changes for connection parameters.

  • connection_async is now async_connect
  • connection_timeout is now timeout
  • connection_persistent is now persistent
  • throw_errors has been removed, replaced by the new exceptions client option.

Please note that using the old parameter names with this new version does not raise any notice.

As an example, the following client configuration for Predis v0.7.x:

$parameters = "tcp://127.0.0.1?connection_async=1&connection_timeout=5&connection_persistent=1&throw_errors=1";
$client = new Predis\Client($parameters);

starting with Predis v0.8.0 must be changed into:

$parameters = "tcp://127.0.0.1?async_connect=1&timeout=5&persistent=1"
$client = new Predis\Client($parameters, array('exceptions' => true));

Additionally, the second parameter of the constructor of Predis\Client does not accept strings or instances of Predis\Profile\ServerProfileInterface like in the past but the server profile must be set by using the profile client option explicitly:

$client = new Predis\Client('tcp://127.0.0.1', '2.4');                      // Wrong
$client = new Predis\Client('tcp://127.0.0.1', array('profile' => '2.4'));  // OK

Redis Cluster

While redis-cluster will not be available until Redis 3.0, Predis already ships with a first working implementation of the logic needed to use this amazing new feature. Configuring the client is simply a matter of passing the list of nodes in the same exact order as they are specified when using redis-trib and setting the cluster client option to redis:

$nodes = array('tcp://10.0.0.1', 'tcp://10.0.0.2', 'tcp://10.0.0.3');
$client = new Predis\Client($nodes, array('cluster' => 'redis'));

Obviously you can rest assured that the good old way of creating a cluster of Redis nodes simply by relying on client-side sharding is still in place and is the default behavior of the client.

Server-side scripting with Lua

Predis supported Redis scripting since v0.7.0 but our high-level abstraction built on top of EVAL and EVALSHA (we call it a scripted command) has been improved to save bandwidth by using the latter by default and falling back transparently to the former when required (that is, when Redis replies to EVALSHA with a -NOSCRIPT error).

Going asynchronous with Predis\Async

Crazy? Maybe, but at least now you can thanks to Predis\Async. This separate project shares the same style and feel of Predis by reusing some of its core classes and is built on top of React to provide a fully-asynchronous implementation of a Redis client. The library is considered experimental and subject to changes in its API, but it already works and can cooperate seamlessy with any other library that makes use of the core event loop abstraction provided by React/EventLoop.

Future development

While this new major release admittedly do not add much features to the plate aside from early support for redis-cluster and a separate project for a fully-asynchronous client, the internals of Predis have been extensively reworked to make the library and its core parts even more easy to extend and reuse, but also with some optimizations put in place. We are at a point in which further changes to the internal architecture of Predis should not be needed for a while, or at least not until we decide to drop compatibility with PHP 5.3 and rewrite stuff to make use of new features introduced in PHP 5.4, which means that we can proceed with experimenting a few ideas such as having core parts of the library implemented in C as an optional PHP extension. Right now you can already use phpiredis to speed thins up, but we can definitely do better that that.

In a more immediate future, aside from addressing eventual bugs the next patch releases in the v0.8.x series will also see the addition of some missing features such as an abstration to deal with redis-sentinel.

Additional notes

Downloads

Useful links

predis - Predis v0.7.3

Published by nrk over 10 years ago

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

This is a maintenance release for the 0.7 series. 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

New commands in the Redis 2.6 server profile

Two new commands have been added to Redis 2.6: BITOP and BITCOUNT.

Scripting abstraction improvements

It is now possible to use negative numbers in the getKeysCount() method to tell Predis\Commands\ScriptedCommand to calculate the actual number of keys used to populate the KEYS array for EVAL starting from the end of the arguments list. You can read this comment for a description of a use case.

We also fixed a bug in Predis\Commands\ServerEvalSHA::getScriptHash().

Additional notes

Downloads

Related projects

Useful links

predis - Predis v0.7.2

Published by nrk over 10 years ago

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

This is a maintenance release for the 0.7 series. 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

New server profile for Redis 2.6

While 2.4 is still the default server profile, you can now use 2.6 instead of dev to use the new commands and features (such as scripting) implemented in Redis 2.6:

$client = new Predis\Client('tcp://127.0.0.1', array('profile' => '2.6'));

The dev profile will target Redis 2.8.

MONITOR and Redis 2.6

The output of MONITOR in Redis 2.6 has been slightly changed resulting in the inability for Predis\MonitorContext to work properly. Now Predis can handle the new output automatically and will add the client field to the returned message object when connected to Redis >= 2.6.

Serializable connections

Connection instances can be serialized and unserialized using serialize() and unserialize(). While probably not useful in most scenarios, this can be handy for example with client-side clustering or replication to lower the overhead of initializing a connection object with many sub-connections since unserializing them can be up to 5x times faster.

$client1 = new Predis\Client();
$serializedConnection = serialize($client->getConnection());

$unserializedConnection = unserialize($serializedConnection);
$client2 = new Predis\Client($unserializedConnection);

Additional notes

Downloads

Related projects

Useful links

predis - Predis v0.7.1

Published by nrk over 10 years ago

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

This is a maintenance release for the 0.7 series that fixes some minor glitches and adds a couple of new features. 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

New PEAR channel

We still want to have PEAR as one of the methods to distribute Predis, but unfortunately PearHub seems to be unmaintained and the generation of new PEAR packages is currently stuck. To overcome this issue we set up a new PEAR channel that will host past and future releases of Predis.

Master / slave replication

This one has been a long-standing feature request but master / slave replication configurations are now supported at client level, which means that it is now possible to configure a group of connections with one master server and one or more slave servers. Commands performing read operations (such as GET) are executed against one of the slaves and the client switches to the master only upon commands performing write operations (such as SET). The configuration of a new client instance for replication is easy, just set the replication client option to true and specify at least two connections, with one of them being the master (see alias=master):

$parameters = array(
    'tcp://127.0.0.1:6379?alias=master',
    'tcp://127.0.0.1:6380?alias=slave1',
);

$options = array('replication' => true);

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

Redis transactions (MULTI / EXEC) force the client to switch to the master server even when the transaction contains read-only operations. The same applies to pipelines, but in this case it is is an implementation detail that could change in future releases.

EVAL and EVALSHA are considered write commands by default since it is not possible for the client to know when a script performs read-only operations or not. Developers can still override this behaviour on a script-basis with a slightly more complex configuration using the replication client option:

$options = array(
    'replication' => function() {
        $replication = new Predis\Network\MasterSlaveReplication();
        $replication->setScriptReadOnly("return redis.call('GET', KEYS[1])");

        return $replication;
    },
);

You can see this example for a complete script using a simple configuration and this one for a more complex one.

Additional notes

Downloads

Related projects

Useful links

predis - Predis v0.7.0

Published by nrk over 10 years ago

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 - Predis v0.6.6

Published by nrk over 10 years ago

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 - Predis v0.6.5

Published by nrk over 10 years ago

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 - Predis v0.6.4

Published by nrk over 10 years ago

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 - Predis v0.6.3

Published by nrk over 10 years ago

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 - Predis v0.6.2

Published by nrk over 10 years ago

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 - Predis v0.6.1

Published by nrk over 10 years ago

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