Repository: erikdubbelboer/phpRedisAdmin (language: php)

Issue:
scanmax issue
<img width="220" alt="image" src="https://github.com/user-attachments/assets/d1c05e2a-2b70-489c-a226-87bfec741f9f">

This is the end of my `config.inc.php`:

```
  // How many entries to fetch using each SCAN command.
  'scansize' => 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'   => 10000
);
```

So, my `scanmax` is set to 10000, yet I get the message that scanmax reached. btw, this db has only arounf 8000 keys. So, the scanmax should never be reached.


Discussion / hints:
Not sure what might be happening, the logic makes sense. You're going to have to debug this yourself: https://github.com/erikdubbelboer/phpRedisAdmin/blob/47f4c678f0cca20709a2587c2704c0ec612de189/index.php#L258
Found the issue.

The `scanmax` must be defined for a server and is ignored when set globally. This is why it didn't work for me. I set it globally.

This is a bug though. If not set on a server level, it should use a globally defined `scanmax`. As is done for all the others.

Additionally, the line you posted has a typo. It's `scanned` with 2 Ns. 
Do you accept a PR for the 2 issues I mentioned above?
Yes please. Sorry I haven't gotten the time to look into it myself yet.
Will do. Might get to it on the weekend..

Fix patch:
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 = '') {
 </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))?>


Test patch: