Commit Graph

55 Commits

Author SHA1 Message Date
michael-grunder
6e0f0d786c Rework generic_z_command to build the command in linear time
This commit changes how we build the Redis protocol string for
ZUNIONSTORE and ZINTERSTORE such that we avoid reallocating
memory for the command buffer for each new key or weight
2013-09-01 07:48:08 -07:00
michael-grunder
f5fc23cbe2 Merge branch 'hotfix/double_precision' into develop 2013-08-31 14:12:56 -07:00
michael-grunder
20a3ef42d8 Merge branch 'feature/mobli_ra_changes' into develop 2013-08-31 14:12:13 -07:00
michael-grunder
8e81c49b55 Performance increase for MGET
This commit changes the way we construct the MGET command
such that we avoid allocating and reallocating the command
string pointer for every new key that is added.

This means that MGET performance scales in a linear way rather
than exponentially.
2013-08-31 11:27:54 -07:00
michael-grunder
535ff5d13f Actually set the precision to 16 places!
Addresses #371
2013-08-15 10:54:41 -07:00
michael-grunder
daef4b73a0 Increase double->string precision
When calling php library methods to convert doubles to strings
we were only keeping 8 digits after the decimal point.  For
double precision numbers, 15 are stable.

Redis uses the C library function strtod() to do the conversion,
which appears to use the first 16 digits for aproximation:
http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/

This hotfix increases the signifigant digits to 16, which I think
is the correct number to pick here.

Addresses issue #371
2013-08-15 10:47:03 -07:00
Emmanuel Merali
ec74ab98df Merge remote-tracking branch 'upstream/develop' into develop
Conflicts:
	library.c
	library.h
	redis.c
	redis_array.c
	redis_array_impl.c
	redis_array_impl.h
	redis_session.c
2013-02-25 00:54:48 +02:00
Emmanuel Merali
acd3245456 Added lazy_connect option to RedisArray
Added an option to let each RedisArray connection connect lazily to
their respective server. This is useful then working with a redis
cluster composed of many shards which are not necessarily in use all at
once.
2013-02-25 00:38:47 +02:00
Emmanuel Merali
4ae635fddf Merge remote-tracking branch 'upstream/master'
Conflicts:
	common.h
2013-02-24 23:41:12 +02:00
Emmanuel Merali
6d3c9990a5 Merged changes from @mobli
New select DB command to RedisArray - Added retry delay on reconnect

Added the possibility to delay each reconnection attempt, including a
random factor to prevent several or many concurrent connections from
trying to reconnect at the same time.
Added the select command to RedisArray to select a DB on every
connections in one instruction.
Also, fixed a compiler warning:
redis_array_impl.c:1115:15: warning: incompatible pointer types
assigning to 'zval **' (aka 'struct _zval_struct **') from 'zval
**(*)[2]' [-Wincompatible-pointer-types]

Conflicts:
	common.h
2013-02-22 09:35:22 -08: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
Emmanuel Merali
d4c7f64131 New select DB command to RedisArray - Added retry delay on reconnect
Added the possibility to delay each reconnection attempt, including a
random factor to prevent several or many concurrent connections from
trying to reconnect at the same time.
Added the select command to RedisArray to select a DB on every
connections in one instruction.
Also, fixed a compiler warning:
redis_array_impl.c:1115:15: warning: incompatible pointer types
assigning to 'zval **' (aka 'struct _zval_struct **') from 'zval
**(*)[2]' [-Wincompatible-pointer-types]
2013-01-29 11:47:36 +02:00
Emmanuel Merali
9ba000c54c Revert "Retry delay - selectDB on array"
This reverts commit 3fb643211e.
2013-01-29 11:40:06 +02:00
Emmanuel Merali
3fb643211e Retry delay - selectDB on array
Added the possibility to delay each reconnection attempt, including a
random factor to prevent several or many concurrent connections from
trying to reconnect at the same time.
Added the select command to RedisArray to select a DB on every
connections in one instruction.
2013-01-21 18:10:16 +02:00
michael-grunder
e1a5145ad2 Changed the way we build the HMSET command such that we don't
continue to destroy and reallocate the command buffer

Added a simply library routine to append to a command buffer
using a smart_str

Made the unit tests work even if you're not compiled with
igbinary

Addresses issue #287
2013-01-18 18:05:02 -08:00
michael-grunder
d4c2c1c91a Add back nuked comment lines 2012-07-02 13:05:59 -07:00
michael-grunder
83f3440b88 PHP 5.4 number encode fix 2012-07-02 12:56:10 -07:00
michael-grunder
8b1a64b43c TSRMLS_CC 2012-05-29 12:29:17 -07:00
maxbeutel
c12a8738be Use module API version instead of PHP_MAJOR/MINOR version. Fix char as argument 2012-05-23 15:29:54 +02:00
maxbeutel
72a041c7f8 use helper for converting from double to string, use _ex version of _php_math_number_format_ex for PHP 5.4 2012-05-23 13:35:58 +02:00
michael-grunder
048e4b2de8 getLastError method 2012-05-11 17:58:54 -07:00
michael-grunder
9c9c63fb46 Initial commit of EVAL and EVALSHA 2012-05-09 17:48:11 -07:00
Nicolas Favre-Felix
a5e53f1bbc Fixed compilation issues with Clang.
(GitHub issue #116).
2012-01-30 21:13:06 +00: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
27fc7c79a2 Bugfix for hgetall used with serializer.
Fixes issue #62.
Also started removing phpunit, it is such a pain to use.
2011-11-03 22:23:15 +00:00
Nicolas Favre-Felix
265feef7aa Merge branch 'master' of https://github.com/Zakay/phpredis into Zakay-master 2011-06-12 19:28:55 +02:00
Ilia Alshanetsky
053d62d506 Significantly optimize the redis_cmd_format_static() and redis_cmd_format() routines. In test cases the performance increase is 3-10 fold for these operations 2011-05-18 12:25:35 -04:00
Nicolas Favre-Felix
6f6c4ff418 Fixed ZTS macros. 2011-04-04 12:28:15 +02:00
Zakay Danial
c561e89ff1 Added support for user specified persistent connection id 2011-02-04 09:45:57 +01:00
Nicolas Favre-Felix
fd03564301 Fix prefix problems with hashes, add more tests. 2011-01-14 10:32:59 +01:00
Nicolas Favre-Felix
2e7e610640 Added key prefix. 2010-12-28 14:12:59 +01:00
Nicolas Favre-Felix
b1142fe27e Merge branch 'master' into serializer
Conflicts:
	library.c
2010-12-28 12:04:36 +01:00
Simon Effenberg
1929e9b5c2 refactore stream closing 2010-12-15 16:40:56 +01:00
Nicolas Favre-Felix
7c2478629d Merge branch 'master' into serializer 2010-12-15 16:10:31 +01:00
Simon Effenberg
bb1bfd2718 fix some missing threaded parameters and added README info 2010-12-15 11:37:53 +01:00
Simon Effenberg
ab9a88ed4f added pconnect, has to be tested and checked 2010-12-15 09:44:35 +01:00
Nicolas Favre-Felix
654d094ab4 Merge branch 'master' of github.com:owlient/phpredis into serializer 2010-12-14 09:03:33 +01:00
Nicolas Favre-Felix
77e57bd836 Trying to fix local issued with floats. 2010-12-13 23:44:22 +01:00
Nicolas Favre-Felix
a4f8456c51 Bugfixes. 2010-12-13 10:39:47 +01:00
Nicolas Favre-Felix
14fbb6b917 Merge branch 'master' into serializer 2010-12-13 10:37:01 +01:00
Nicolas Favre-Felix
5a4eb10695 Fixed a large number of warnings when compiled with -Wall (thanks to github user lstrojny for the initial work on this). 2010-12-13 10:18:42 +01:00
Nicolas Favre-Felix
3d0bb74249 Serializing option for HGET/HSET/HGETALL. 2010-12-12 19:39:53 +01:00
Nicolas Favre-Felix
b2afc58654 First work on serializer. 2010-12-08 23:47:25 +01:00
Nicolas Favre-Felix
f283d361ac Fix for double values on older PHP versions. 2010-11-17 09:29:05 +01:00
Nicolas Favre-Felix
90366e8f49 Throw exception when the connection fails repeatedly. 2010-10-25 10:36:56 +02:00
Nicolas Favre-Felix
25eb12fb2c Added floating-point timeout for better precision. 2010-10-06 14:37:42 +02:00
Nicolas Favre-Felix
c67e2ddf74 Re-added HMGET + doc & unit tests. 2010-09-20 17:33:59 +02:00
Nicolas Favre-Felix
c6c002119a Fixed INFO, TYPE for MULTI/EXEC context. 2010-09-19 16:47:10 +02:00
Nicolas Favre-Felix
6edae7c4b0 Fixed ZTS problems. 2010-08-17 14:24:09 +02:00
Nasreddine Bouafif
43b43fce7b publish/subscribe/unsubscribe implementation, fiw warnings 2010-06-11 13:31:50 +02:00