@@ -1008,19 +1008,38 @@ _**Description**_: Scan the keyspace for keys
10081008* LONG, Optional* : Count of keys per iteration (only a suggestion to Redis)
10091009
10101010##### * Return value*
1011- * Array, boolean* : This function will return an array of keys or FALSE if there are no more keys
1011+ * Array, boolean* : This function will return an array of keys or FALSE if Redis returned zero keys
10121012
10131013##### * Example*
10141014~~~
1015- $it = NULL; /* Initialize our iterator to NULL */
1015+
1016+ /* Without enabling Redis::SCAN_RETRY (default condition) */
1017+ $it = NULL;
10161018do {
1017- // Use global option $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); to ignore empty results
1019+ // Scan for some keys
10181020 $arr_keys = $redis->scan($it);
1019- foreach($arr_keys as $str_key) {
1020- echo "Here is a key: $str_key\n";
1021+
1022+ // Redis may return empty results, so protect against that
1023+ if ($arr_keys !== FALSE) {
1024+ foreach($arr_keys as $str_key) {
1025+ echo "Here is a key: $str_key\n";
1026+ }
10211027 }
10221028} while ($it > 0);
10231029echo "No more keys to scan!\n";
1030+
1031+ /* With Redis::SCAN_RETRY enabled */
1032+ $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
1033+ $it = NULL;
1034+
1035+ /* phpredis will retry the SCAN command if empty results are returned from the
1036+ server, so no empty results check is required. */
1037+ while ($arr_keys = $redis->scan($it)) {
1038+ foreach ($arr_keys as $str_key) {
1039+ echo "Here is a key: $str_key\n";
1040+ }
1041+ }
1042+ echo "No more keys to scan!\n";
10241043~~~
10251044
10261045### object
0 commit comments