Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2022-01-20 22:46:08 +0300
committermichael-grunder <michael.grunder@gmail.com>2022-01-30 21:21:13 +0300
commit0264de1824b03fb2d0ad515b4d4ec019cd2dae70 (patch)
treeaead3d1a04ee1583452cb429265c294423e67ef1 /tests
parent8689ab1c17a13034d9c8d0b7a011331cae9e5311 (diff)
A small test for key scanning in RedisArray
See: #2055
Diffstat (limited to 'tests')
-rw-r--r--tests/RedisArrayTest.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/RedisArrayTest.php b/tests/RedisArrayTest.php
index a8526886..5a20d271 100644
--- a/tests/RedisArrayTest.php
+++ b/tests/RedisArrayTest.php
@@ -166,6 +166,43 @@ class Redis_Array_Test extends TestSuite
}
}
+ /* Scan a whole key and return the overall result */
+ protected function execKeyScan($cmd, $key) {
+ $res = [];
+
+ $it = NULL;
+ do {
+ $chunk = $this->ra->$cmd($key, $it);
+ foreach ($chunk as $field => $value) {
+ $res[$field] = $value;
+ }
+ } while ($it !== 0);
+
+ return $res;
+ }
+
+ public function testKeyScanning() {
+ $h_vals = ['foo' => 'bar', 'baz' => 'bop'];
+ $z_vals = ['one' => 1, 'two' => 2, 'three' => 3];
+ $s_vals = ['mem1', 'mem2', 'mem3'];
+
+ $this->ra->del(['scan-hash', 'scan-set', 'scan-zset']);
+
+ $this->ra->hMSet('scan-hash', $h_vals);
+ foreach ($z_vals as $k => $v)
+ $this->ra->zAdd('scan-zset', $v, $k);
+ $this->ra->sAdd('scan-set', ...$s_vals);
+
+ $s_scan = $this->execKeyScan('sScan', 'scan-set');
+ $this->assertTrue(count(array_diff_key(array_flip($s_vals), array_flip($s_scan))) == 0);
+
+ $this->assertEquals($h_vals, $this->execKeyScan('hScan', 'scan-hash'));
+
+ $z_scan = $this->execKeyScan('zScan', 'scan-zset');
+ $this->assertTrue(count($z_scan) == count($z_vals) &&
+ count(array_diff_key($z_vals, $z_scan)) == 0 &&
+ array_sum($z_scan) == array_sum($z_vals));
+ }
}
class Redis_Rehashing_Test extends TestSuite