Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 593ba01

Browse filesBrowse files
Check for dragonfly_version in HELLO response
DragonflyDB will report to be Redis but also include `dragonfly_version` in the hello response, which we can use to identify the fork. Also fix parsing of the `HELLO` response for `serverName()` and `serverVersion()`. Starting in Redis 8.0 there seem to always be modules running, which the previous function was not expecting or parsing.
1 parent b48aa0d commit 593ba01
Copy full SHA for 593ba01

3 files changed

+29-14Lines changed: 29 additions & 14 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎library.c‎

Copy file name to clipboardExpand all lines: library.c
+26-13Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,26 +2018,31 @@ static int
20182018
redis_hello_response(INTERNAL_FUNCTION_PARAMETERS,
20192019
RedisSock *redis_sock, zval *z_tab, void *ctx)
20202020
{
2021-
int numElems;
20222021
zval z_ret, *zv;
2022+
int numElems;
20232023

2024-
if (read_mbulk_header(redis_sock, &numElems) < 0) {
2025-
if (IS_ATOMIC(redis_sock)) {
2026-
RETVAL_FALSE;
2027-
} else {
2028-
add_next_index_bool(z_tab, 0);
2029-
}
2030-
return FAILURE;
2031-
}
2024+
if (read_mbulk_header(redis_sock, &numElems) < 0)
2025+
goto fail;
20322026

20332027
array_init(&z_ret);
2034-
redis_mbulk_reply_zipped_raw_variant(redis_sock, &z_ret, numElems);
2028+
2029+
if (redis_read_multibulk_recursive(redis_sock, numElems, 0, &z_ret) != SUCCESS ||
2030+
array_zip_values_recursive(&z_ret) != SUCCESS)
2031+
{
2032+
zval_dtor(&z_ret);
2033+
goto fail;
2034+
}
20352035

20362036
if (redis_sock->hello.server) {
20372037
zend_string_release(redis_sock->hello.server);
20382038
}
2039-
zv = zend_hash_str_find(Z_ARRVAL(z_ret), ZEND_STRL("server"));
2040-
redis_sock->hello.server = zv ? zval_get_string(zv) : ZSTR_EMPTY_ALLOC();
2039+
2040+
if ((zv = zend_hash_str_find(Z_ARRVAL(z_ret), ZEND_STRL("dragonfly_version")))) {
2041+
redis_sock->hello.server = zend_string_init(ZEND_STRL("dragonfly"), 0);
2042+
} else {
2043+
zv = zend_hash_str_find(Z_ARRVAL(z_ret), ZEND_STRL("server"));
2044+
redis_sock->hello.server = zv ? zval_get_string(zv) : ZSTR_EMPTY_ALLOC();
2045+
}
20412046

20422047
if (redis_sock->hello.version) {
20432048
zend_string_release(redis_sock->hello.version);
@@ -2063,6 +2068,14 @@ redis_hello_response(INTERNAL_FUNCTION_PARAMETERS,
20632068
}
20642069

20652070
return SUCCESS;
2071+
2072+
fail:
2073+
if (IS_ATOMIC(redis_sock)) {
2074+
RETVAL_FALSE;
2075+
} else {
2076+
add_next_index_bool(z_tab, 0);
2077+
}
2078+
return FAILURE;
20662079
}
20672080

20682081

@@ -4302,7 +4315,7 @@ redis_read_multibulk_recursive(RedisSock *redis_sock, long long elements, int st
43024315
elements--;
43034316
}
43044317

4305-
return 0;
4318+
return SUCCESS;
43064319
}
43074320

43084321
static int
Collapse file

‎redis.c‎

Copy file name to clipboardExpand all lines: redis.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,7 @@ redis_sock_read_multibulk_multi_reply_loop(INTERNAL_FUNCTION_PARAMETERS,
21312131

21322132
int num = atol(inbuf + 1);
21332133

2134-
if (num > 0 && redis_read_multibulk_recursive(redis_sock, num, 0, &z_ret) < 0) {
2134+
if (num > 0 && redis_read_multibulk_recursive(redis_sock, num, 0, &z_ret) != SUCCESS) {
21352135
return FAILURE;
21362136
}
21372137
}
Collapse file

‎tests/RedisTest.php‎

Copy file name to clipboardExpand all lines: tests/RedisTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,7 @@ public function testServerInfo() {
24762476
$this->markTestSkipped();
24772477

24782478
$hello = $this->execHello();
2479+
24792480
if ( ! $this->assertArrayKey($hello, 'server') ||
24802481
! $this->assertArrayKey($hello, 'version'))
24812482
{
@@ -2486,6 +2487,7 @@ public function testServerInfo() {
24862487
$this->assertEquals($hello['version'], $this->redis->serverVersion());
24872488

24882489
$info = $this->redis->info();
2490+
24892491
$cmd1 = $info['total_commands_processed'];
24902492

24912493
/* Shouldn't hit the server */

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.