Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02c91d5

Browse files
Fix RPOP to unserialize/decompress data.
Fixes #2329
1 parent 43f7e72 commit 02c91d5

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

cluster_library.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ cluster_pop_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx)
17671767
if (ctx == NULL) {
17681768
cluster_bulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
17691769
} else if (ctx == PHPREDIS_CTX_PTR) {
1770-
cluster_mbulk_raw_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
1770+
cluster_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
17711771
} else {
17721772
ZEND_ASSERT(!"memory corruption?");
17731773
}

library.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ redis_pop_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_
14881488
if (ctx == NULL) {
14891489
return redis_string_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab, NULL);
14901490
} else if (ctx == PHPREDIS_CTX_PTR) {
1491-
return redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab, NULL);
1491+
return redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab, NULL);
14921492
} else {
14931493
ZEND_ASSERT(!"memory corruption?");
14941494
return FAILURE;

tests/RedisTest.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,18 +1137,13 @@ public function testlPop()
11371137
// PUSH, POP : RPUSH, RPOP
11381138
public function testrPop()
11391139
{
1140-
// rpush => tail
1141-
// lpush => head
1142-
11431140
$this->redis->del('list');
11441141

11451142
$this->redis->rPush('list', 'val');
11461143
$this->redis->rPush('list', 'val2');
1147-
$this->redis->lPush('list', 'val3');
1148-
1149-
// 'list' = [ 'val3', 'val', 'val2']
1144+
$this->redis->lPush('list', 'val3');
11501145

1151-
$this->assertEquals('val2', $this->redis->rPop('list'));
1146+
$this->assertEquals('val2', $this->redis->rPop('list'));
11521147
if (version_compare($this->version, "6.2.0") < 0) {
11531148
$this->assertEquals('val', $this->redis->rPop('list'));
11541149
$this->assertEquals('val3', $this->redis->rPop('list'));
@@ -1157,17 +1152,29 @@ public function testrPop()
11571152
}
11581153
$this->assertEquals(FALSE, $this->redis->rPop('list'));
11591154

1160-
// testing binary data
11611155

1162-
$this->redis->del('list');
1163-
$this->assertEquals(1, $this->redis->rPush('list', gzcompress('val1')));
1164-
$this->assertEquals(2, $this->redis->rPush('list', gzcompress('val2')));
1165-
$this->assertEquals(3, $this->redis->rPush('list', gzcompress('val3')));
1156+
$this->redis->del('list');
1157+
$this->assertEquals(1, $this->redis->rPush('list', gzcompress('val1')));
1158+
$this->assertEquals(2, $this->redis->rPush('list', gzcompress('val2')));
1159+
$this->assertEquals(3, $this->redis->rPush('list', gzcompress('val3')));
1160+
1161+
$this->assertEquals('val3', gzuncompress($this->redis->rPop('list')));
1162+
$this->assertEquals('val2', gzuncompress($this->redis->rPop('list')));
1163+
$this->assertEquals('val1', gzuncompress($this->redis->rPop('list')));
1164+
}
11661165

1167-
$this->assertEquals('val3', gzuncompress($this->redis->rPop('list')));
1168-
$this->assertEquals('val2', gzuncompress($this->redis->rPop('list')));
1169-
$this->assertEquals('val1', gzuncompress($this->redis->rPop('list')));
1166+
/* Regression test for GH #2329 */
1167+
public function testrPopSerialization() {
1168+
$this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
11701169

1170+
$this->redis->del('rpopkey');
1171+
$this->redis->rpush('rpopkey', ['foo'], ['bar']);
1172+
$this->assertEquals([['bar'], ['foo']], $this->redis->rpop('rpopkey', 2));
1173+
1174+
$this->redis->rpush('rpopkey', ['foo'], ['bar']);
1175+
$this->assertEquals([['foo'], ['bar']], $this->redis->lpop('rpopkey', 2));
1176+
1177+
$this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
11711178
}
11721179

11731180
public function testblockingPop() {

0 commit comments

Comments
 (0)