Commit Graph

137 Commits

Author SHA1 Message Date
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
b2a57c1f9f Merge branch 'hotfix/serializer_leak' into develop 2013-03-16 11:40:36 -07:00
michael-grunder
a4627bb94b Fixes a memory leak, and possible undefined behavior if we have
a serialization failure and just return the raw contents of a key.

Addresses issue #315
2013-03-15 16:34:05 -07:00
michael-grunder
d6c29e4348 Merge branch 'hotfix/fix_return_values' into develop 2013-02-24 17:52:56 -08:00
michael-grunder
703476ce01 Fix each place we're erroring out but return a value as the
methods are int returns

Resolves issues pertaining to #303
2013-02-24 17:51:56 -08:00
michael-grunder
0816289454 Merge branch 'hotfix/add_retval_zipped_wreply' into develop 2013-02-24 16:47:57 -08:00
michael-grunder
9954974778 Return a proper value
redis_sock_read_multibulk_reply_zipped_with_flag should always return
a value.  We merged in a change that handled a certain error condition
that was using RETURN_FALSE (and therefore not returning a value)

Simply changed this to RETVAL_FALSE and return -1;
2013-02-24 16:45:11 -08:00
michael-grunder
e457d9813d Don't return a value from a void function 2013-02-24 16:32:40 -08: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
Nicolas Favre-Felix
a4784b4de7 Merge branch 'hotfix/issue-229' into develop 2013-02-17 16:32:08 +00:00
Nicolas Favre-Felix
4231d70b66 Merge branch 'master' of https://github.com/rnamiki/phpredis into rnamiki-master 2013-02-17 16:07:39 +00: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
55dd05356d Merge remote-tracking branch 'kotas/opt-read-timeout'
Conflicts:
	library.c
2013-02-11 12:42:49 -08: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
07369ed1fb Merge pull request #272 from pepve/brpoplpush
Thanks for the pull, merging.
2013-01-16 09:19:56 -08:00
michael-grunder
93f77be960 Checks for tv.tv_usec as well as tv.tv_sec when setting the read
timeout option on our socket.  We were actually ignoring timeouts
< 1 second because of this.

Nice catch by @xiaoyjy

Fixes #286
2013-01-13 21:59:13 -08:00
Pepijn Verlaan
c7cb312345 Fix brpoplpush timeout reply handling 2012-11-16 09:53:19 +01:00
kotas
3764a6cd80 add Redis::OPT_READ_TIMEOUT option for issue #70 2012-10-04 22:18:18 +09:00
Nicolas Favre-Felix
6153477c4f Extend getLastError to all calls
Fixes GitHub issue #245.
2012-09-09 20:38:30 +01:00
Nicolas Favre-Felix
9138299c0c Enable conditional compilation for igbinary option 2012-09-02 11:19:14 +01:00
Remi Collet
c6e13befdc missing TSRMLS_CC, fix ZTS build 2012-08-29 16:48:44 +02:00
Nicolas Favre-Felix
9c224410f3 Merge pull request #225 from pavel-krush/master
Fix segfault when using persistent connections
2012-08-29 00:41:51 -07:00
rnamiki
a65b609201 fixed bug different type command returns 2012-08-15 18:14:25 +09:00
michael-grunder
89bdaf22cb Remove a debug line 2012-08-08 16:20:19 -07:00
michael-grunder
691786bc7f Properly apply a prefix on sort(), sortAsc(), and sortDesc() methods with an
included unit test to make sure it's working properly.

This fixes issue #226
2012-08-08 16:09:57 -07:00
neon
dedee1f7ae fix segfault when using persistent connections 2012-08-07 01:42:08 +07:00
michael-grunder
83f3440b88 PHP 5.4 number encode fix 2012-07-02 12:56:10 -07:00
Nicolas Favre-Felix
82a5f70670 Merge branch 'master' of https://github.com/michael-grunder/phpredis into michael-grunder 2012-05-29 22:34:54 +01:00
maxbeutel
158d90b035 Fixing serializer initialization and destruction in PHP 5.4. 2012-05-29 22:18:58 +01:00
michael-grunder
8b1a64b43c TSRMLS_CC 2012-05-29 12:29:17 -07:00
Nicolas Favre-Felix
38e2cca3cf Merge branch '0-reconnect-select' 2012-05-27 22:26:08 +01:00
Nicolas Favre-Felix
2e70c5a5a9 Merge branch 'reconnect-select' of https://github.com/0/phpredis into 0-reconnect-select 2012-05-27 22:24:58 +01: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
maxbeutel
c1bc92bf48 replace remaining occurences of _php_math_number_format 2012-05-23 12:08:37 +02:00
michael-grunder
0ca8a1df21 Merge remote-tracking branch 'upstream/master' 2012-05-17 14:48:31 -07:00
Nicolas Favre-Felix
f8f552e3b2 Cleaner handling of large values on 32-bits.
Tested on 32-bits, addresses GitHub issue #174.
2012-05-17 22:45:32 +01:00
michael-grunder
048e4b2de8 getLastError method 2012-05-11 17:58:54 -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
Dmitri Iouchtchenko
db3c3c5d2a Added SELECT after reconnect
This prevents the DB number from being reset to zero after a timeout and
subsequent automatic reconnect.
2012-05-08 22:50:36 -04:00
michael-grunder
d66c893e01 Updated redis_cmd_format_static to specifically take a long, and changed PEXIPREAT to use a long rather than an int 2012-05-05 13:45:50 -07:00
michael-grunder
d59b53b6b5 Implemented INCRBYFLOAT and HINCRBYFLOAT 2012-05-04 12:12:03 -07:00
Nicolas Favre-Felix
4cf7677d05 Make sure stream exists when checking for EOF.
Addressing issue #143.
2012-03-11 13:40:16 +00:00
Nicolas Favre-Felix
8ebb811294 Fix for issue #134 (missing port for sessions).
The port is set to 6379 if not specified.
2012-02-27 13:47:19 +00:00
Nicolas Favre-Felix
5d8839f15e Fixed small leak with info().
Thanks to @kotas for reporting and @chobie for fixing.
This closes GitHub issue #125.
2012-01-30 20:43:09 +00: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
87dfaf4212 Properly parse new-style info blocks. 2011-12-29 14:16:47 +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
yanli
dd42be6a87 change exception message 2011-12-07 15:36:13 +08:00