Skip to content

Commit 32e0fa2

Browse files
committed
Fixed issue phpredis#68.
1 parent 71f4de5 commit 32e0fa2

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

redis.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -852,18 +852,36 @@ PHP_METHOD(Redis, getMultiple)
852852
&pointer) == SUCCESS;
853853
zend_hash_move_forward_ex(arr_hash, &pointer)) {
854854

855+
char *key;
856+
int key_len;
857+
zval *z_tmp = NULL;
858+
855859
if (Z_TYPE_PP(data) == IS_STRING) {
856-
char *old_cmd = NULL;
857-
if(*cmd) {
858-
old_cmd = cmd;
859-
}
860-
cmd_len = redis_cmd_format(&cmd, "%s$%d" _NL "%s" _NL
861-
, cmd, cmd_len
862-
, Z_STRLEN_PP(data), Z_STRVAL_PP(data), Z_STRLEN_PP(data));
863-
if(old_cmd) {
864-
efree(old_cmd);
865-
}
866-
elements++;
860+
key = Z_STRVAL_PP(data);
861+
key_len = Z_STRLEN_PP(data);
862+
} else { /* not a string, copy and convert. */
863+
MAKE_STD_ZVAL(z_tmp);
864+
*z_tmp = **data;
865+
zval_copy_ctor(z_tmp);
866+
convert_to_string(z_tmp);
867+
868+
key = Z_STRVAL_P(z_tmp);
869+
key_len = Z_STRLEN_P(z_tmp);
870+
}
871+
char *old_cmd = NULL;
872+
if(*cmd) {
873+
old_cmd = cmd;
874+
}
875+
cmd_len = redis_cmd_format(&cmd, "%s$%d" _NL "%s" _NL
876+
, cmd, cmd_len
877+
, key_len, key, key_len);
878+
if(old_cmd) {
879+
efree(old_cmd);
880+
}
881+
elements++;
882+
if(z_tmp) {
883+
zval_dtor(z_tmp);
884+
efree(z_tmp);
867885
}
868886
}
869887

tests/TestRedis.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public function testMultiple() {
211211
$this->redis->set('k1', 'v1');
212212
$this->redis->set('k2', 'v2');
213213
$this->redis->set('k3', 'v3');
214+
$this->redis->set(1, 'test');
214215

215216
$this->assertEquals(array('v1'), $this->redis->getMultiple(array('k1')));
216217
$this->assertEquals(array('v1', 'v3', false), $this->redis->getMultiple(array('k1', 'k3', 'NoKey')));
@@ -219,6 +220,8 @@ public function testMultiple() {
219220

220221
$this->redis->set('k5', '$1111111111');
221222
$this->assertEquals(array(0 => '$1111111111'), $this->redis->getMultiple(array('k5')));
223+
224+
$this->assertEquals(array(0 => 'test'), $this->redis->getMultiple(array(1))); // non-string
222225
}
223226

224227
public function testMultipleBin() {

0 commit comments

Comments
 (0)