Skip to content

Commit 2351d12

Browse files
authored
Merge pull request phpredis#1833 from phpredis/issue-1831
Issue phpredis#1831
2 parents b2cffff + 566fdee commit 2351d12

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

library.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,10 @@ redis_read_xinfo_response(RedisSock *redis_sock, zval *z_ret, int elements)
17131713
switch (type) {
17141714
case TYPE_BULK:
17151715
if ((data = redis_sock_read_bulk_reply(redis_sock, li)) == NULL) {
1716-
goto failure;
1716+
if (!key) goto failure;
1717+
add_assoc_null_ex(z_ret, key, len);
1718+
efree(key);
1719+
key = NULL;
17171720
} else if (key) {
17181721
add_assoc_stringl_ex(z_ret, key, len, data, li);
17191722
efree(data);

tests/RedisTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6064,6 +6064,21 @@ public function testXInfo()
60646064
}
60656065
}
60666066

6067+
/* Regression test for issue-1831 (XINFO STREAM on an empty stream) */
6068+
public function testXInfoEmptyStream() {
6069+
/* Configure an empty stream */
6070+
$this->redis->del('s');
6071+
$this->redis->xAdd('s', '*', ['foo' => 'bar']);
6072+
$this->redis->xTrim('s', 0);
6073+
6074+
$arr_info = $this->redis->xInfo('STREAM', 's');
6075+
6076+
$this->assertTrue(is_array($arr_info));
6077+
$this->assertEquals(0, $arr_info['length']);
6078+
$this->assertEquals(NULL, $arr_info['first-entry']);
6079+
$this->assertEquals(NULL, $arr_info['last-entry']);
6080+
}
6081+
60676082
public function testInvalidAuthArgs() {
60686083
$obj_new = $this->newInstance();
60696084

0 commit comments

Comments
 (0)