@@ -166,6 +166,43 @@ public function testKeyDistributor()
166166 }
167167 }
168168
169+ /* Scan a whole key and return the overall result */
170+ protected function execKeyScan ($ cmd , $ key ) {
171+ $ res = [];
172+
173+ $ it = NULL ;
174+ do {
175+ $ chunk = $ this ->ra ->$ cmd ($ key , $ it );
176+ foreach ($ chunk as $ field => $ value ) {
177+ $ res [$ field ] = $ value ;
178+ }
179+ } while ($ it !== 0 );
180+
181+ return $ res ;
182+ }
183+
184+ public function testKeyScanning () {
185+ $ h_vals = ['foo ' => 'bar ' , 'baz ' => 'bop ' ];
186+ $ z_vals = ['one ' => 1 , 'two ' => 2 , 'three ' => 3 ];
187+ $ s_vals = ['mem1 ' , 'mem2 ' , 'mem3 ' ];
188+
189+ $ this ->ra ->del (['scan-hash ' , 'scan-set ' , 'scan-zset ' ]);
190+
191+ $ this ->ra ->hMSet ('scan-hash ' , $ h_vals );
192+ foreach ($ z_vals as $ k => $ v )
193+ $ this ->ra ->zAdd ('scan-zset ' , $ v , $ k );
194+ $ this ->ra ->sAdd ('scan-set ' , ...$ s_vals );
195+
196+ $ s_scan = $ this ->execKeyScan ('sScan ' , 'scan-set ' );
197+ $ this ->assertTrue (count (array_diff_key (array_flip ($ s_vals ), array_flip ($ s_scan ))) == 0 );
198+
199+ $ this ->assertEquals ($ h_vals , $ this ->execKeyScan ('hScan ' , 'scan-hash ' ));
200+
201+ $ z_scan = $ this ->execKeyScan ('zScan ' , 'scan-zset ' );
202+ $ this ->assertTrue (count ($ z_scan ) == count ($ z_vals ) &&
203+ count (array_diff_key ($ z_vals , $ z_scan )) == 0 &&
204+ array_sum ($ z_scan ) == array_sum ($ z_vals ));
205+ }
169206}
170207
171208class Redis_Rehashing_Test extends TestSuite
0 commit comments