8000 Check for `dragonfly_version` in `HELLO` response by michael-grunder · Pull Request #2656 · phpredis/phpredis · GitHub
[go: up one dir, main page]

Skip to content

Check for dragonfly_version in HELLO response #2656

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 1 commit into from
May 5, 2025
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
39 changes: 26 additions & 13 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -2018,26 +2018,31 @@ static int
redis_hello_response(INTERNAL_FUNCTION_PARAMETERS,
RedisSock *redis_sock, zval *z_tab, void *ctx)
{
int numElems;
zval z_ret, *zv;
int numElems;

if (read_mbulk_header(redis_sock, &numElems) < 0) {
if (IS_ATOMIC(redis_sock)) {
RETVAL_FALSE;
} else {
add_next_index_bool(z_tab, 0);
}
return FAILURE;
}
if (read_mbulk_header(redis_sock, &numElems) < 0)
goto fail;

array_init(&z_ret);
redis_mbulk_reply_zipped_raw_variant(redis_sock, &z_ret, numElems);

if (redis_read_multibulk_recursive(redis_sock, numElems, 0, &z_ret) != SUCCESS ||
array_zip_values_recursive(&z_ret) != SUCCESS)
{
zval_dtor(&z_ret);
goto fail;
}

if (redis_sock->hello.server) {
zend_string_release(redis_sock->hello.server);
}
zv = zend_hash_str_find(Z_ARRVAL(z_ret), ZEND_STRL("server"));
redis_sock->hello.server = zv ? zval_get_string(zv) : ZSTR_EMPTY_ALLOC();

if ((zv = zend_hash_str_find(Z_ARRVAL(z_ret), ZEND_STRL("dragonfly_version")))) {
redis_sock->hello.server = zend_string_init(ZEND_STRL("dragonfly"), 0);
} else {
zv = zend_hash_str_find(Z_ARRVAL(z_ret), ZEND_STRL("server"));
redis_sock->hello.server = zv ? zval_get_string(zv) : ZSTR_EMPTY_ALLOC();
}

if (redis_sock->hello.version) {
zend_string_release(redis_sock->hello.version);
Expand All @@ -2063,6 +2068,14 @@ redis_hello_response(INTERNAL_FUNCTION_PARAMETERS,
}

return SUCCESS;

fail:
if (IS_ATOMIC(redis_sock)) {
RETVAL_FALSE;
} else {
add_next_index_bool(z_tab, 0);
}
return FAILURE;
}


Expand Down Expand Up @@ -4302,7 +4315,7 @@ redis_read_multibulk_recursive(RedisSock *redis_sock, long long elements, int st
elements--;
}

return 0;
return SUCCESS;
}

static int
Expand Down
2 changes: 1 addition & 1 deletion redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ redis_sock_read_multibulk_multi_reply_loop(INTERNAL_FUNCTION_PARAMETERS,

int num = atol(inbuf + 1);

if (num > 0 && redis_read_multibulk_recursive(redis_sock, num, 0, &z_ret) < 0) {
if (num > 0 && redis_read_multibulk_recursive(redis_sock, num, 0, &z_ret) != SUCCESS) {
return FAILURE;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,7 @@ public function testServerInfo() {
$this->markTestSkipped();

$hello = $this->execHello();

if ( ! $this->assertArrayKey($hello, 'server') ||
! $this->assertArrayKey($hello, 'version'))
{
Expand All @@ -2486,6 +2487,7 @@ public function testServerInfo() {
$this->assertEquals($hello['version'], $this->redis->serverVersion());

$info = $this->redis->info();

$cmd1 = $info['total_commands_processed'];

/* Shouldn't hit the server */
Expand Down
Loading
0