244 Commits

Author SHA1 Message Date
michael-grunder 1d47fc8813 Bump! 2014-03-15 10:20:55 -07:00
michael-grunder 6c37fa301d Merge branch 'feature/pubsub_cmd' into develop 2014-03-15 10:14:41 -07:00
michael-grunder e74ffe0366 Implemented BITPOS command
This commit introduces the new BITPOS redis command
http://redis.io/commands/bitpos
2014-03-03 06:23:38 -08:00
michael-grunder f200730fe9 _serialize method
This commit adds a utility method as a counterpart to the _unserialize
utility method, allowing users to manually serialize data themselves
before sending it to Redis.  This could be useful for calls going through
EVAL, as phpredis can't automatically serialize/unserialize in that case.

Addresses #431
2014-02-04 11:55:08 -08:00
michael-grunder 48ae8e52f6 Implement PUBSUB command
This commit implements the Redis PUBSUB command, a new command
available since Redis 2.8.0 and described here:
http://redis.io/commands/pubsub

Addresses #427
2014-01-21 14:50:34 -08:00
michael-grunder ab553893f9 SCAN and variants
This commit introduces support for the Redis SCAN, HSCAN, SSCAN,
and ZSCAN commands.

In the case of HSCAN, SSCAN, and ZSCAN, we take a key and iterator
as required arguments, and for SCAN just an iterator.  Matching
the Redis commands, each variant can optionally take a pattern
to match against and a count value which hints at Redis how many
keys to return at a time.

When scanning keys or members (especially with a large keyspace when
searching for a pattern), Redis will sometimes return an empty result
of keys/members.  PHPRedis can be set up to abstract this from the
caller by setting:

$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);

Which instructs PHPRedis to keep retrying the scan until members are
returned OR the iteration completes (Redis returns to us a zero iterator).

By default this option is set to Redis::SCAN_NORETRY, meaning that
empty results are possible, requiring an explicit check for FALSE in the
scanning loop, like so:

```php
$it = NULL;
while(($arr_keys = $redis->scan($it, "*pattern*"))!==FALSE) {
	print_r($arr_keys);
}
```
2013-12-14 10:51:03 -08:00
michael-grunder 77afbe3dac Implement WAIT command
This commit implements the new WAIT command which currently lives
in redis unstable, along with a unit test.

Also added myself to the README.markdown file, as well as a link to
"the twitter".
2013-12-07 14:08:18 -08:00
vostok4 b7e8b3b64e Fix compilation errors on Win32 with VC11
This brings the W32 compilation fixes done by @char101 up to date and
allows building of php_redis.dll with VC11 on Win32 (allows for a php5.5
version).
2013-10-10 13:07:01 +02:00
Nicolas Favre-Felix f4960ddec2 Release version 2.2.4 2013-09-01 20:24:09 +01:00
michael-grunder 7207aae8aa Add SLOWLOG command
Add support for the various slowlog commands you can execute
in Redis, including:

SLOWLOG GET [len]
SLOWLOG RESET
SLOWLOG LIST
2013-08-27 21:26:51 -07:00
michael-grunder 3e6d5b60d6 Cutting a release for 2.2.3. Added myself as a maintainer
in the header files
2013-04-28 11:09:58 -07:00
michael-grunder e914485313 Merge branch 'hotfix/inspection_methods' into develop
Conflicts:
	php_redis.h
	redis.c
2013-03-27 11:21:02 -07:00
michael-grunder ef792320e7 Introspection methods
This commit adds methods to get information about the state
of our phpredis object, such as what host/port we are connected
to, our timeout, etc...

The following methods have been added:

getHost()
getPort()
getDBNum()
getTimeout()
getReadTimeout()
isConnected()
getPersistentID()
getAuth()

In addition, there is a small memory leak fix when a persistent id
was specifically passed to connect() (it wasn't beeing freed).

Addresses issue #320
2013-03-27 10:21:18 -07:00
michael-grunder 9a5196ed2e CLIENT Commands
This commit adds support for the CLIENT commands (list, getname,
setname, kill).

You can call them like so:

$redis->client('list');
$redis->client('getname');
$redis->client('setname', $name);
$redis->client('kill', $ip_port);

Solves issue #300
2013-02-16 17:57:32 -08:00
michael-grunder b4735e578b Merge branch 'master' of github.com:nicolasff/phpredis 2012-09-10 08:25:52 -07:00
Nicolas Favre-Felix 5855cfc2ca Add clearLastError 2012-09-09 22:09:27 +01:00
michael-grunder d1b1216852 PSUBSCRIBE
Implemented PSUBSCRIBE/PUNSUBSCRIBE and changed the present
subscribe and unsubscribe functions into generic versions
that can handle both cases.
2012-09-09 08:13:44 -07:00
Nicolas Favre-Felix 6f7087fbfe Removed executable bit on source code 2012-09-02 19:05:29 +01:00
Nicolas Favre-Felix 4197a7ffed Tag 2.2.2 2012-08-29 10:25:54 +01:00
michael-grunder f1231c98e2 TIME command 2012-06-05 09:04:10 -07:00
michael-grunder 8283007248 MIGRAGE command 2012-05-29 10:37:45 -07:00
michael-grunder 0ca8a1df21 Merge remote-tracking branch 'upstream/master' 2012-05-17 14:48:31 -07:00
Nicolas Favre-Felix 2c1875cebd Add BITCOUNT.
Included docs.
2012-05-17 21:48:44 +01:00
Nicolas Favre-Felix 2a3a7eac92 Add GITOP.
Included docs.
2012-05-17 21:44:19 +01:00
michael-grunder 048e4b2de8 getLastError method 2012-05-11 17:58:54 -07:00
michael-grunder dc36368624 _prefix, _unserialize methods 2012-05-10 16:17:47 -07:00
michael-grunder d18388b3a0 DUMP, RESTORE commands 2012-05-10 14:45:48 -07:00
michael-grunder 96af61b109 SCRIPT command 2012-05-10 13:28:08 -07:00
michael-grunder 9c9c63fb46 Initial commit of EVAL and EVALSHA 2012-05-09 17:48:11 -07:00
michael-grunder d59b53b6b5 Implemented INCRBYFLOAT and HINCRBYFLOAT 2012-05-04 12:12:03 -07:00
Nicolas Favre-Felix 261c5734fd Add PEXPIREAT.
Fixes GitHub issue #147.
2012-04-29 18:18:58 +01:00
Nicolas Favre-Felix 7bff3ddd15 Add PTTL. 2012-04-29 18:17:45 +01:00
Nicolas Favre-Felix fe8e2fbebc Add PEXPIRE. 2012-04-29 18:15:12 +01:00
Nicolas Favre-Felix 171a9699ec Add PSETEX. 2012-04-29 18:13:20 +01:00
Nicolas Favre-Felix c4a5370a82 Add ECHO.
Covered by unit test; fixes GitHub issue #165.
2012-04-16 13:16:27 +01:00
Nicolas Favre-Felix 882c7dc92b Tagged 2.2.1 2012-04-09 17:04:56 +01:00
michael-grunder 2544afb1fc Move latent DISCARD into stuff into a proper __destruct(or) 2012-02-27 14:04:53 -08:00
Nicolas Favre-Felix 99387710de Merge branch 'master' of https://github.com/imvu/phpredis into imvu-master 2012-01-02 16:03:53 +00:00
Nicolas Favre-Felix 1a1a81bf62 Fixed issue with HDEL in serialize mode.
Addresses GitHub issue #114. Fixed unit test as well.
2011-12-30 13:50:39 +00:00
David Edler ccc824a779 add config function 2011-12-29 14:40:12 +01:00
Eric Hohenstein 39df0b7a2c fixing issue with re-connect logic
There was an issue with the re-connect logic such that it would sometimes only partially apply a transaction. The redis_check_eof() function in library.c was automatically and invisibly re-connecting to the redis server when php_stream_eof() returned non-zero. If this happened to happen after a transaction had been partially stored, the server was rolling back the transaction but the phpredis library was continuing as if it was still applying the transaction so the remaining commands were being applied immediately. The result was that the portion of the transaction after the re-connect was applied (although not atomically) but the portion before the reconnect was thrown away by the server.

This change causes the phpredis library to fail (by throwing a RedisException) instead of reconnecting if the client session is in multi mode or it is watching any keys. Either of these conditions indicate that the server has lost the state of the session and the client needs to rebuild it. Because transactions can fail due to watched keys having been changed, clients that use transactions should already be coded to handle transaction failures using retry logic. With this change, clients that use transactions when talking to redis servers that use connection timeout, they will have to add a try...catch within the transaction retry loop to handle this type of failure. Clients that do not use transactions and clients that use transactions with redis servers that do not use connection timeout will be unaffected.

Perhaps not coincidentally, this change also fixes a well known but previously not well understood bug that causes RedisExceptions to be thrown with a message like  "protocol error, got '*' as reply type byte". My company began integrating redis into our service that handles 500,000 daily active users in April of this year. Prior to this fix, when we had our redis server connection timeout set to 5 seconds we would get hundreds of those error messages showing up in our php error logs per day. This wasn't a huge problem but it was concerning enough to raise the connection timeout to 30 seconds which reduced the rate of the errors but didn't eliminate them. At one point we had a process that was failing repeatedly with this error with a 30 second timeout so we had to raise the timeout all the way up to 300 seconds. A long timeout is not idea for a high throughput website like ours since it can cause failures to cascade from one system to another due to resource limits and requests holding on to connections for a long time. After introducing this fix roughly a month ago we have not had a single instance of RedisException show up in our php error logs (except for legitimate errors related to the server being down) even after lowering the server timeout back down to 5 seconds.

To reproduce the problem without this fix, set the redis server timeout configuration to 3 seconds and use the following test php script:

<?php

define('MAX_FAILURES', 1);

function get_redis() {
    $r = new Redis();
    $r->connect('localhost');
    return $r;
}

$r = get_redis();

$r->set('foo', '123');
$r->set('bar', 'abc');

if (isset($_GET['trans']) && $_GET['trans']) {
    $completed = false;
    $failures = 0;
    while (!$completed && ($failures < MAX_FAILURES)) {
        try {
            $trans = $r->multi();
            $trans->set('foo', $_GET['foo']);
            if (isset($_GET['sleep']) && $_GET['sleep']) {
                sleep($_GET['sleep']);
            }
            $trans->set('bar', $_GET['bar']);
            var_export($trans->exec());
            echo '<br/>';
            $completed = true;
        } catch (RedisException $e) {
            echo 'transaction failed<br/>';
            $failures++;
            $r = get_redis();
        }
    }
} else {
    $r->set('foo', $_GET['foo']);
    if (isset($_GET['sleep']) && $_GET['sleep']) {
        sleep($_GET['sleep']);
    }
    $r->set('bar', $_GET['bar']);
}

echo $r->get('foo');
echo '<br/>';
echo $r->get('bar');

?>

****************************
*** Results without this fix
****************************

foo=bar&bar=baz&trans=0&sleep=0
bar
baz

foo=bar&bar=baz&trans=1&sleep=0
array ( 0 => true, 1 => true, )
bar
baz

foo=bar&bar=baz&trans=0&sleep=30
bar
baz

foo=bar&bar=baz&trans=1&sleep=30
NULL
123
baz

Notice in this last example the call to exec() did not return anything and the value of the key 'bar' was modified by the transaction but the value of the key 'foo' was not even though the calls to set() on both keys were made between a call to multi() and a call to exec().

*************************
*** Results with this fix
*************************

foo=bar&bar=baz&trans=0&sleep=0
bar
baz

foo=bar&bar=baz&trans=1&sleep=0
array ( 0 => true, 1 => true, )
bar
baz

foo=bar&bar=baz&trans=0&sleep=30
bar
baz

foo=bar&bar=baz&trans=1&sleep=30
transaction failed
123
abc

Notice in the last example where the transaction failed message is printed, it is necessary to explicitly reconnect to the redis server. Trying to reuse the same redis object after it has failed to reconnect will result in a segmentation fault. I believe this was an existing problem with the phpredis library and it is not addressed by this change.
2011-12-22 12:26:36 -08:00
Nicolas Favre-Felix b783d7e3aa Better variadic function, variadic HDEL. 2011-08-01 22:37:22 +01:00
Erik Dubbelboer 26cf871e47 Added resetStat function 2011-07-08 18:07:13 +02:00
Charles c9a6ce2cf4 Build fix for win32 (phpredis 2.1.3) 2011-06-30 21:17:23 +07:00
Nicolas Favre-Felix 43bc590502 version bump after tagging mistake 2011-05-20 21:50:53 +02:00
Nicolas Favre-Felix b1f9a726c3 Version bump to 2.1.1 2011-05-20 21:48:42 +02:00
Nicolas Favre-Felix 765b9a7f41 Added BRPOPLPUSH. 2011-04-28 13:03:43 +02:00
Nicolas Favre-Felix fbdf65c75c Added OBJECT command. 2011-04-06 14:32:39 +02:00
Nicolas Favre-Felix a086b0e55b Add missing ZREMRANGEBYRANK + doc, tests. 2011-01-24 16:26:40 +01:00
Nicolas Favre-Felix 426609531f Add HSETNX. 2011-01-24 16:08:09 +01:00