Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Yet another Redis client for PHP.
PHP C++
branch: master
Failed to load latest commit information.
ext First commit.
lib Moved some code in format_comamand() in order to use most commands in…
test Moved some code in format_comamand() in order to use most commands in…
README.rdoc

README.rdoc

php5-redis

Yet another PHP client class for Redis.

This one is (almost) a no-brainer. It takes commands, sends them to Redis using the multibulk protocol, reads the reply and returns it back. Sometimes the return will be particularly formatted (ie. bools or hashes), and some commands may have particular attributes (eg: mget or sort).

Features

It's currently compatible with Redis 1.2.x and supports most Redis 1.3.x features like hashes, zrank, publish/subscribe, multi/exec, etc.

You wait for messages with the +listen()+ method, after subscribing. Since listen will block the execution of the PHP script, you might not be able to send other subscribe or unsubscribe calls, though.

Examples:

$r = new Redis\Client();

$r->set('mykey', 'foobar');  # => 'OK'
$r->get('mykey');            # => 'foobar'
$r->setnx('mykey', 'foo');   # => false
$r->getset('mykey', 'foo');  # => 'foobar'

$r->incr('counter');         # => 1
$r->incrby('counter', 3);    # => 4
$r->decr('counter');         # => 3

$r->del('counter');          # => 1
$r->get('counter');          # => null

Please note that some commands may not work when called in a pipeline (eg. sort).

Clusters

I'm not sure this Redis\Cluster class is a good idea, since an official (and thus far better) redis-cluster shall appear some time after Redis 2.0 is out.

Anyway, clusters are supported through the Redis\Cluster class, which is a drop-in replacement for the Redis\Client class, except for a few limitations:

  • pipeline() doesn't support MGET and MSETNX, because it's too complicated to handle replies correctly.

  • MSETNX is supported but requires that all the keys are on a single server, since you can't ensure that all the keys -or none- are set when keys are sharded between servers.

  • SORT as the same problem: all the involved keys must be on a single server.

  • MULTI/EXEC won't work as expected. Redis\Cluster should remember the MULTI command and send it whenever a new server is contacted. Contacted servers should be remembered too, in order for EXEC and DISCARD to work.

  • PUB/SUB won't work too.

  • etc.

Everything else is supported, even MGET and MSET.

Extension

Someday it might be ported to be a PHP extension, written in C or C++.

License

php5-redis is distributed under the MIT license.

Copyright (c) 2010 julien Portalier <ysbaddaden@gmail.com>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.