Skip to content

Commit 590c753

Browse files
Capture error for multibulk responses
Addresses phpredis#540
1 parent 243cca9 commit 590c753

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

library.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ PHP_REDIS_API int redis_sock_set_err(RedisSock *redis_sock, const char *msg, int
15671567
PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
15681568
{
15691569
char inbuf[1024];
1570-
int numElems;
1570+
int numElems, err_len;
15711571
zval *z_multi_result;
15721572

15731573
if(-1 == redis_check_eof(redis_sock TSRMLS_CC)) {
@@ -1587,6 +1587,12 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
15871587
IF_MULTI_OR_PIPELINE() {
15881588
add_next_index_bool(z_tab, 0);
15891589
} else {
1590+
/* Capture our error if redis has given us one */
1591+
if (inbuf[0] == '-') {
1592+
err_len = strlen(inbuf+1) - 2;
1593+
redis_sock_set_err(redis_sock, inbuf+1, err_len);
1594+
}
1595+
15901596
RETVAL_FALSE;
15911597
}
15921598
return -1;

tests/TestRedis.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -2499,13 +2499,21 @@ public function testSetRange() {
24992499
}
25002500

25012501
public function testObject() {
2502-
$this->redis->del('key');
2502+
/* Version 3.0.0 (represented as >= 2.9.0 in redis info) and moving
2503+
* forward uses "embstr" instead of "raw" for small string values */
2504+
if (version_compare($this->version, "2.9.0", "lt")) {
2505+
$str_small_encoding = "raw";
2506+
} else {
2507+
$str_small_encoding = "embstr";
2508+
}
2509+
2510+
$this->redis->del('key');
25032511
$this->assertTrue($this->redis->object('encoding', 'key') === FALSE);
25042512
$this->assertTrue($this->redis->object('refcount', 'key') === FALSE);
25052513
$this->assertTrue($this->redis->object('idletime', 'key') === FALSE);
25062514

25072515
$this->redis->set('key', 'value');
2508-
$this->assertTrue($this->redis->object('encoding', 'key') === "raw");
2516+
$this->assertTrue($this->redis->object('encoding', 'key') === $str_small_encoding);
25092517
$this->assertTrue($this->redis->object('refcount', 'key') === 1);
25102518
$this->assertTrue($this->redis->object('idletime', 'key') === 0);
25112519

0 commit comments

Comments
 (0)