github predis/predis v0.7.1
Predis v0.7.1

latest releases: v3.0.0-alpha1, v2.2.2, v2.2.1...
9 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

Don't miss a new predis release

NewReleases is sending notifications on new releases.