Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix Null Bulk String response parsing in cluster library #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions cluster_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,11 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust
RETVAL_TRUE;
break;
case TYPE_BULK:
RETVAL_STRINGL(r->str, r->len);
if (r->len < 0) {
RETVAL_NULL();
} else {
RETVAL_STRINGL(r->str, r->len);
}
break;
case TYPE_MULTIBULK:
array_init(z_arr);
Expand All @@ -1896,8 +1900,12 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust
add_next_index_bool(&c->multi_resp, 1);
break;
case TYPE_BULK:
add_next_index_stringl(&c->multi_resp, r->str, r->len);
efree(r->str);
if (r->len < 0) {
add_next_index_null(&c->multi_resp);
} else {
add_next_index_stringl(&c->multi_resp, r->str, r->len);
efree(r->str);
}
break;
case TYPE_MULTIBULK:
cluster_mbulk_variant_resp(r, &c->multi_resp);
Expand Down
63 changes: 63 additions & 0 deletions tests/RedisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,69 @@ public function testEvalSHA() {
$this->assertTrue(1 === $this->redis->eval($scr,Array($str_key), 1));
$this->assertTrue(1 === $this->redis->evalsha($sha,Array($str_key), 1));
}

public function testEvalBulkResponse() {
$str_key1 = uniqid() . '-' . rand(1,1000) . '{hash}';
$str_key2 = uniqid() . '-' . rand(1,1000) . '{hash}';

$this->redis->script($str_key1, 'flush');
$this->redis->script($str_key2, 'flush');

$scr = "return {KEYS[1],KEYS[2]}";

$result = $this->redis->eval($scr,Array($str_key1, $str_key2), 2);

$this->assertTrue($str_key1 === $result[0]);
$this->assertTrue($str_key2 === $result[1]);
}

public function testEvalBulkResponseMulti() {
$str_key1 = uniqid() . '-' . rand(1,1000) . '{hash}';
$str_key2 = uniqid() . '-' . rand(1,1000) . '{hash}';

$this->redis->script($str_key1, 'flush');
$this->redis->script($str_key2, 'flush');

$scr = "return {KEYS[1],KEYS[2]}";

$this->redis->multi();
$this->redis->eval($scr,Array($str_key1, $str_key2), 2);

$result = $this->redis->exec();

$this->assertTrue($str_key1 === $result[0][0]);
$this->assertTrue($str_key2 === $result[0][1]);
}

public function testEvalBulkEmptyResponse() {
$str_key1 = uniqid() . '-' . rand(1,1000) . '{hash}';
$str_key2 = uniqid() . '-' . rand(1,1000) . '{hash}';

$this->redis->script($str_key1, 'flush');
$this->redis->script($str_key2, 'flush');

$scr = "for _,key in ipairs(KEYS) do redis.call('SET', key, 'value') end";

$result = $this->redis->eval($scr,Array($str_key1, $str_key2), 2);

$this->assertTrue(null === $result);
}

public function testEvalBulkEmptyResponseMulti() {
$str_key1 = uniqid() . '-' . rand(1,1000) . '{hash}';
$str_key2 = uniqid() . '-' . rand(1,1000) . '{hash}';

$this->redis->script($str_key1, 'flush');
$this->redis->script($str_key2, 'flush');

$scr = "for _,key in ipairs(KEYS) do redis.call('SET', key, 'value') end";

$this->redis->multi();
$this->redis->eval($scr,Array($str_key1, $str_key2), 2);
$result = $this->redis->exec();

$this->assertTrue(null === $result[0]);
}

/* Cluster specific introspection stuff */
public function testIntrospection() {
Expand Down