Skip to content

Commit c8fc6a0

Browse files
authored
fix: scanmax behavior (#212)
* fix: typo * fix: scanmax behavior
1 parent 47f4c67 commit c8fc6a0

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

includes/common.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,22 @@
9595
$server['keys'] = $config['keys'];
9696
}
9797

98+
if (!isset($config['scansize'])) {
99+
$config['scansize'] = 1000;
100+
}
101+
102+
if (!isset($config['scanmax'])) {
103+
$config['scanmax'] = 0;
104+
}
105+
98106
if (!isset($server['scansize'])) {
99107
$server['scansize'] = $config['scansize'];
100108
}
101109

110+
if (!isset($server['scanmax'])) {
111+
$server['scanmax'] = $config['scanmax'];
112+
}
113+
102114
if (!isset($server['serialization'])) {
103115
if (isset($config['serialization'])) {
104116
$server['serialization'] = $config['serialization'];

includes/config.sample.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8).
3434
'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default).
3535
'scansize' => 1000, // How many entries to fetch using each SCAN command for this server (default uses config default).
36-
'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.
36+
'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).
3737
),*/
3838
),
3939

@@ -85,4 +85,7 @@
8585

8686
// How many entries to fetch using each SCAN command.
8787
'scansize' => 1000
88+
89+
// The total number of entries to fetch. Set to 0 or -1 for no limit.
90+
'scanmax' => 0
8891
);

index.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@
1010
} else {
1111
$next = 0;
1212
$keys = array();
13-
$scansize = $server['scansize'];
1413
while (true) {
15-
$r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $scansize);
14+
$r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $server['scansize']);
1615
$next = $r[0];
1716
$keys = array_merge($keys, $r[1]);
1817
if ($next == 0) {
1918
break;
2019
}
21-
if (count($keys) >= $server['scanmax']) {
20+
if ($server['scanmax'] > 0 && count($keys) >= $server['scanmax']) {
2221
break;
2322
}
24-
$scansize = min($server['scanmax'] - count($keys), $server['scansize']);
2523
}
2624
}
2725

@@ -255,7 +253,7 @@ function getDbInfo($d, $info, $padding = '') {
255253
</div>
256254
<div id="keys">
257255
<div class="info">
258-
scaned <?php echo count($keys) ?> keys<?php echo (count($keys) >= $server['scanmax']) ? ', reached scanmax' : '' ?>
256+
scanned <?php echo count($keys) ?> keys<?php echo ($server['scanmax'] > 0 && count($keys) >= $server['scanmax']) ? ', reached scanmax' : '' ?>
259257
</div>
260258
<ul>
261259
<?php print_namespace($namespaces, 'Keys', '', empty($namespaces))?>

0 commit comments

Comments
 (0)