diff options
-rw-r--r-- | cluster_library.c | 20 | ||||
-rw-r--r-- | redis_cluster.c | 2 | ||||
-rw-r--r-- | tests/RedisTest.php | 45 |
3 files changed, 19 insertions, 48 deletions
diff --git a/cluster_library.c b/cluster_library.c index d55a77b4..b49afc72 100644 --- a/cluster_library.c +++ b/cluster_library.c @@ -1785,21 +1785,23 @@ PHPAPI void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS, { zval *z_result; - // Verify our reply type byte is correct and that this isn't a NULL - // (e.g. -1 count) multi bulk response. - if(c->reply_type != TYPE_MULTIBULK || c->reply_len == -1) { + /* Return FALSE if we didn't get a multi-bulk response */ + if (c->reply_type != TYPE_MULTIBULK) { CLUSTER_RETURN_FALSE(c); } - // Allocate array + /* Allocate our array */ MAKE_STD_ZVAL(z_result); array_init(z_result); - // Call our specified callback - if(cb(c->cmd_sock, z_result, c->reply_len, ctx TSRMLS_CC)==FAILURE) { - zval_dtor(z_result); - FREE_ZVAL(z_result); - CLUSTER_RETURN_FALSE(c); + /* Consume replies as long as there are more than zero */ + if (c->reply_len > 0) { + /* Call our specified callback */ + if (cb(c->cmd_sock, z_result, c->reply_len, ctx TSRMLS_CC)==FAILURE) { + zval_dtor(z_result); + FREE_ZVAL(z_result); + CLUSTER_RETURN_FALSE(c); + } } // Success, make this array our return value diff --git a/redis_cluster.c b/redis_cluster.c index cc16d1b8..e23f4c27 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -1113,7 +1113,7 @@ PHP_METHOD(RedisCluster, srandmember) { /* {{{ proto string RedisCluster::strlen(string key) */ PHP_METHOD(RedisCluster, strlen) { - CLUSTER_PROCESS_KW_CMD("STRLEN", redis_key_cmd, cluster_bulk_resp, 1); + CLUSTER_PROCESS_KW_CMD("STRLEN", redis_key_cmd, cluster_long_resp, 1); } /* {{{ proto long RedisCluster::lpush(string key, string val1, ... valN) */ diff --git a/tests/RedisTest.php b/tests/RedisTest.php index ec3129bf..1280022d 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -670,6 +670,7 @@ class Redis_Test extends TestSuite $this->assertTrue($this->redis->append('key', 'val2') === 8); $this->assertTrue($this->redis->get('key') === 'val1val2'); + $this->redis->del('keyNotExist'); $this->assertTrue($this->redis->append('keyNotExist', 'value') === 5); $this->assertTrue($this->redis->get('keyNotExist') === 'value'); @@ -757,8 +758,7 @@ class Redis_Test extends TestSuite } public function testblockingPop() { - - // non blocking blPop, brPop + // non blocking blPop, brPop $this->redis->del('list'); $this->redis->lPush('list', 'val1'); $this->redis->lPush('list', 'val2'); @@ -768,44 +768,13 @@ class Redis_Test extends TestSuite $this->redis->del('list'); $this->redis->lPush('list', 'val1'); $this->redis->lPush('list', 'val2'); - $this->assertTrue($this->redis->brPop(array('list'), 1) === array('list', 'val1')); - $this->assertTrue($this->redis->brPop(array('list'), 1) === array('list', 'val2')); + $this->assertTrue($this->redis->brPop(array('list'), 1) === array('list', 'val1')); + $this->assertTrue($this->redis->brPop(array('list'), 1) === array('list', 'val2')); - // blocking blpop, brpop + // blocking blpop, brpop $this->redis->del('list'); - $this->assertTrue($this->redis->blPop(array('list'), 1) === array()); - $this->assertTrue($this->redis->brPop(array('list'), 1) === array()); - - // TODO: fix this broken test. -// $this->redis->del('list'); -// $params = array( -// 0 => array("pipe", "r"), -// 1 => array("pipe", "w"), -// 2 => array("file", "/dev/null", "w") -// ); -// if(function_exists('proc_open')) { -// $env = array('PHPREDIS_key' =>'list', 'PHPREDIS_value' => 'value'); -// $process = proc_open('php', $params, $pipes, '/tmp', $env); -// -// if (is_resource($process)) { -// fwrite($pipes[0], '<?php -// sleep(2); -// $r = new Redis; -// $r->connect("'.self::HOST.'", '.self::PORT.'); -// if("'.addslashes(self::AUTH).'") { -// $r->auth("'.addslashes(self::AUTH).'"); -// } -// $r->lPush($_ENV["PHPREDIS_key"], $_ENV["PHPREDIS_value"]); -// ?' . '>'); -// -// fclose($pipes[0]); -// fclose($pipes[1]); -// $re = proc_close($process); -// -// $this->assertTrue($this->redis->blPop(array('list'), 5) === array("list", "value")); -// } -// } - + $this->assertTrue($this->redis->blPop(array('list'), 1) === array()); + $this->assertTrue($this->redis->brPop(array('list'), 1) === array()); } public function testllen() |