diff options
author | michael-grunder <michael.grunder@gmail.com> | 2020-03-03 09:13:33 +0300 |
---|---|---|
committer | Michael Grunder <michael.grunder@gmail.com> | 2022-09-29 09:18:53 +0300 |
commit | 98fda1b870171a800a587512bcc59c8bdbd0869a (patch) | |
tree | 724e97cb7e1886f1015c3d5ed7a55d5889a9105f | |
parent | a98605f216449479cf27599244c25cbf415ed226 (diff) |
Make sure we set an error for key based scans
See #1661
-rw-r--r-- | library.c | 10 | ||||
-rw-r--r-- | tests/RedisClusterTest.php | 1 | ||||
-rw-r--r-- | tests/RedisTest.php | 11 |
3 files changed, 20 insertions, 2 deletions
@@ -386,19 +386,25 @@ redis_check_eof(RedisSock *redis_sock, zend_bool no_retry, zend_bool no_throw) return -1; } - PHP_REDIS_API int redis_sock_read_scan_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, REDIS_SCAN_TYPE type, zend_long *iter) { REDIS_REPLY_TYPE reply_type; long reply_info; - char *p_iter; + char err[4096], *p_iter; + size_t errlen; /* Our response should have two multibulk replies */ if(redis_read_reply_type(redis_sock, &reply_type, &reply_info)<0 || reply_type != TYPE_MULTIBULK || reply_info != 2) { + if (reply_type == TYPE_ERR) { + if (redis_sock_gets(redis_sock, err, sizeof(err), &errlen) == 0) { + redis_sock_set_err(redis_sock, err, errlen); + } + } + return -1; } diff --git a/tests/RedisClusterTest.php b/tests/RedisClusterTest.php index 6daa93bb..908e1e58 100644 --- a/tests/RedisClusterTest.php +++ b/tests/RedisClusterTest.php @@ -49,6 +49,7 @@ class Redis_Cluster_Test extends Redis_Test { public function testTlsConnect() { return $this->markTestSkipped(); } public function testReset() { return $this->markTestSkipped(); } public function testInvalidAuthArgs() { return $this->markTestSkipped(); } + public function testScanErrors() { return $this->markTestSkipped(); } public function testlMove() { return $this->markTestSkipped(); } public function testlPos() { return $this->marktestSkipped(); } diff --git a/tests/RedisTest.php b/tests/RedisTest.php index 6ef56490..9c06b64e 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -5701,6 +5701,17 @@ class Redis_Test extends TestSuite $this->assertEquals(0, $i_p_count); } + /* Make sure we capture errors when scanning */ + public function testScanErrors() { + $this->redis->set('scankey', 'simplekey'); + + foreach (['sScan', 'hScan', 'zScan'] as $str_method) { + $it = NULL; + $this->redis->$str_method('scankey', $it); + $this->assertTrue(strpos($this->redis->getLastError(), 'WRONGTYPE') === 0); + } + } + // // HyperLogLog (PF) commands // |