Skip to content

Commit 092f83f

Browse files
authored
Limit the max number of keys when scanning (#206)
* Add parameter scan_max * Limit the max number of keys when scanning * Rename parameter scan_max to scanmax
1 parent 7bf3365 commit 092f83f

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

includes/config.environment.inc.php

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$config['keys'] = getenv('KEYS') ?: false;
1212
$config['maxkeylen'] = getenv('MAX_KEY_LEN') ?: 100;
1313
$config['scansize'] = getenv('SCAN_SIZE') ?: 1000;
14+
$config['scanmax'] = getenv('SCAN_MAX') ?: 1000;
1415
$config['seperator'] = getenv('SEPERATOR') ?: ':';
1516
$config['showEmptyNamespaceAsKey'] = getenv('SHOW_EMPTY_NAMESPACE_AS_KEY') ?: false;
1617

@@ -64,6 +65,7 @@
6465
'port' => $server_port,
6566
'filter' => $config['filter'],
6667
'scansize' => $config['scansize'],
68+
'scanmax' => $config['scanmax'],
6769
);
6870

6971
if (!empty($server_auth)) {

includes/config.sample.inc.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
'flush' => false, // Set to true to enable the flushdb button for this instance.
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).
35-
'scansize' => 1000 // How many entries to fetch using each SCAN command for this server (default uses config default).
35+
'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.
3637
),*/
3738
),
3839

index.php

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
$next = $r[0];
1818
$keys = array_merge($keys, $r[1]);
1919

20+
if (count($keys) >= $server['scanmax']) {
21+
break;
22+
}
23+
2024
if ($next == 0) {
2125
break;
2226
}

0 commit comments

Comments
 (0)