diff --git a/includes/common.inc.php b/includes/common.inc.php index 075ca16..c13424b 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -95,10 +95,22 @@ $server['keys'] = $config['keys']; } +if (!isset($config['scansize'])) { + $config['scansize'] = 1000; +} + +if (!isset($config['scanmax'])) { + $config['scanmax'] = 0; +} + if (!isset($server['scansize'])) { $server['scansize'] = $config['scansize']; } +if (!isset($server['scanmax'])) { + $server['scanmax'] = $config['scanmax']; +} + if (!isset($server['serialization'])) { if (isset($config['serialization'])) { $server['serialization'] = $config['serialization']; diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index 13f4a2c..2732d97 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -33,7 +33,7 @@ 'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8). 'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default). 'scansize' => 1000, // How many entries to fetch using each SCAN command for this server (default uses config default). - 'scanmax' => 1000, // In each query, SCAN command may be executed several times. To shorten the duration, it is recommended to limit the total number of entries to fetch. + 'scanmax' => 1000, // In each query, SCAN command may be executed several times. To shorten the duration, it is recommended to limit the total number of entries to fetch (default uses config default). ),*/ ), @@ -85,4 +85,7 @@ // How many entries to fetch using each SCAN command. 'scansize' => 1000 + + // The total number of entries to fetch. Set to 0 or -1 for no limit. + 'scanmax' => 0 ); diff --git a/index.php b/index.php index 056abeb..b513947 100644 --- a/index.php +++ b/index.php @@ -10,18 +10,16 @@ } else { $next = 0; $keys = array(); - $scansize = $server['scansize']; while (true) { - $r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $scansize); + $r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $server['scansize']); $next = $r[0]; $keys = array_merge($keys, $r[1]); if ($next == 0) { break; } - if (count($keys) >= $server['scanmax']) { + if ($server['scanmax'] > 0 && count($keys) >= $server['scanmax']) { break; } - $scansize = min($server['scanmax'] - count($keys), $server['scansize']); } } @@ -255,7 +253,7 @@ function getDbInfo($d, $info, $padding = '') {
- scaned keys= $server['scanmax']) ? ', reached scanmax' : '' ?> + scanned keys 0 && count($keys) >= $server['scanmax']) ? ', reached scanmax' : '' ?>