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

Skip to content

Commit 98fda1b

Browse files
Make sure we set an error for key based scans
See #1661
1 parent a98605f commit 98fda1b

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

library.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,25 @@ redis_check_eof(RedisSock *redis_sock, zend_bool no_retry, zend_bool no_throw)
386386
return -1;
387387
}
388388

389-
390389
PHP_REDIS_API int
391390
redis_sock_read_scan_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
392391
REDIS_SCAN_TYPE type, zend_long *iter)
393392
{
394393
REDIS_REPLY_TYPE reply_type;
395394
long reply_info;
396-
char *p_iter;
395+
char err[4096], *p_iter;
396+
size_t errlen;
397397

398398
/* Our response should have two multibulk replies */
399399
if(redis_read_reply_type(redis_sock, &reply_type, &reply_info)<0
400400
|| reply_type != TYPE_MULTIBULK || reply_info != 2)
401401
{
402+
if (reply_type == TYPE_ERR) {
403+
if (redis_sock_gets(redis_sock, err, sizeof(err), &errlen) == 0) {
404+
redis_sock_set_err(redis_sock, err, errlen);
405+
}
406+
}
407+
402408
return -1;
403409
}
404410

tests/RedisClusterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function testConnectException() { return $this->markTestSkipped(); }
4949
public function testTlsConnect() { return $this->markTestSkipped(); }
5050
public function testReset() { return $this->markTestSkipped(); }
5151
public function testInvalidAuthArgs() { return $this->markTestSkipped(); }
52+
public function testScanErrors() { return $this->markTestSkipped(); }
5253

5354
public function testlMove() { return $this->markTestSkipped(); }
5455
public function testlPos() { return $this->marktestSkipped(); }

tests/RedisTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5701,6 +5701,17 @@ public function testZScan() {
57015701
$this->assertEquals(0, $i_p_count);
57025702
}
57035703

5704+
/* Make sure we capture errors when scanning */
5705+
public function testScanErrors() {
5706+
$this->redis->set('scankey', 'simplekey');
5707+
5708+
foreach (['sScan', 'hScan', 'zScan'] as $str_method) {
5709+
$it = NULL;
5710+
$this->redis->$str_method('scankey', $it);
5711+
$this->assertTrue(strpos($this->redis->getLastError(), 'WRONGTYPE') === 0);
5712+
}
5713+
}
5714+
57045715
//
57055716
// HyperLogLog (PF) commands
57065717
//

0 commit comments

Comments
 (0)