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
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2017-04-10 22:46:46 +0300
committermichael-grunder <michael.grunder@gmail.com>2017-04-10 22:46:46 +0300
commitc5991fe7d122ca0d74c8dcbd51db369bc9e3c2f3 (patch)
tree2eebf4ae3fc00dd1a6fbbe51e8e3dfd02b610e9a /README.markdown
parentf0c25a21ac6489e74d827b6c196790d4d926d461 (diff)
Show examples for SCAN_RETRY and SCAN_NORETRY
Diffstat (limited to 'README.markdown')
-rw-r--r--README.markdown29
1 files changed, 24 insertions, 5 deletions
diff --git a/README.markdown b/README.markdown
index 9571afa7..98df2278 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1008,19 +1008,38 @@ _**Description**_: Scan the keyspace for keys
*LONG, Optional*: Count of keys per iteration (only a suggestion to Redis)
##### *Return value*
-*Array, boolean*: This function will return an array of keys or FALSE if there are no more keys
+*Array, boolean*: This function will return an array of keys or FALSE if Redis returned zero keys
##### *Example*
~~~
-$it = NULL; /* Initialize our iterator to NULL */
+
+/* Without enabling Redis::SCAN_RETRY (default condition) */
+$it = NULL;
do {
- // Use global option $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); to ignore empty results
+ // Scan for some keys
$arr_keys = $redis->scan($it);
- foreach($arr_keys as $str_key) {
- echo "Here is a key: $str_key\n";
+
+ // Redis may return empty results, so protect against that
+ if ($arr_keys !== FALSE) {
+ foreach($arr_keys as $str_key) {
+ echo "Here is a key: $str_key\n";
+ }
}
} while ($it > 0);
echo "No more keys to scan!\n";
+
+/* With Redis::SCAN_RETRY enabled */
+$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
+$it = NULL;
+
+/* phpredis will retry the SCAN command if empty results are returned from the
+ server, so no empty results check is required. */
+while ($arr_keys = $redis->scan($it)) {
+ foreach ($arr_keys as $str_key) {
+ echo "Here is a key: $str_key\n";
+ }
+}
+echo "No more keys to scan!\n";
~~~
### object