Skip to content

Commit

Permalink
fix: scanmax behavior (#212)
Browse files Browse the repository at this point in the history
* fix: typo

* fix: scanmax behavior
  • Loading branch information
tessus authored Dec 8, 2024
1 parent 47f4c67 commit c8fc6a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
12 changes: 12 additions & 0 deletions includes/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
5 changes: 4 additions & 1 deletion includes/config.sample.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
),*/
),

Expand Down Expand Up @@ -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
);
8 changes: 3 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

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

0 comments on commit c8fc6a0

Please sign in to comment.