From 7fd4ab8b92f404e2fe08614eab055674e940a1d2 Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Tue, 29 Oct 2024 12:36:37 +0100 Subject: [PATCH] Replace Redis Stats GUI with the newer Valkey Stats GUI --- CHANGES.md | 4 + README.md | 8 +- UPGRADE.md | 2 +- flushdb.php | 8 +- index.php | 2 +- lib/{redis-stats => valkey-stats}/LICENSE | 0 lib/{redis-stats => valkey-stats}/config.php | 6 +- .../flushdb.php.inc | 65 ++++++----- .../valkey-stats.php.inc} | 102 ++++++++++-------- tests/behat/tool_redis.feature | 6 +- thirdpartylibs.xml | 6 +- 11 files changed, 119 insertions(+), 90 deletions(-) rename lib/{redis-stats => valkey-stats}/LICENSE (100%) rename lib/{redis-stats => valkey-stats}/config.php (93%) rename lib/{redis-stats => valkey-stats}/flushdb.php.inc (73%) rename lib/{redis-stats/redis-stats.php.inc => valkey-stats/valkey-stats.php.inc} (88%) diff --git a/CHANGES.md b/CHANGES.md index 0932d1f..1c083cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,10 @@ moodle-tool_redis Changes ------- +### Unreleased + +* 2024-10-29 - Replace Redis Stats GUI with the newer Valkey Stats GUI + ### v4.4-r1 * 2024-08-24 - Development: Rename master branch to main, please update your clones. diff --git a/README.md b/README.md index 03de271..3b43354 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ Motivation for this plugin For performance reasons, Moodle should always be run with a Caching backend. Redis is such a caching backend which Moodle can connect to. Unfortunately, Redis is kind of a black box and doesn't provide a management interface by default. -Luckily, there are some free Redis management GUIs out there with Redis Stats by Helmut K. C. Tessarek (https://github.com/tessus/redis-stats) being a really nice and compact one. As a Moodle server administrator, you can just throw Redis Stats somewhere onto your Moodle server and get a Redis management GUI instantly. However, this approach requires that you protect Redis Stats from unauthorized access manually in your webserver and comes with the downside that Redis Stats is located outside Moodle. +Luckily, there are some free Redis management GUIs out there with Valkey Stats by Helmut K. C. Tessarek (https://github.com/tessus/valkey-stats) being a really nice and compact one. As a Moodle server administrator, you can just throw Valkey Stats somewhere onto your Moodle server and get a Redis management GUI instantly. However, this approach requires that you protect Valkey Stats from unauthorized access manually in your webserver and comes with the downside that Valkey Stats is located outside Moodle. -For these reasons, we have packaged Redis Stats as a very simple Moodle admin tool providing it within Moodle site adminstration for Moodle administrators only. +For these reasons, we have packaged Valkey Stats as a very simple Moodle admin tool providing it within Moodle site adminstration for Moodle administrators only. Installation @@ -171,5 +171,5 @@ It was contributed to the Moodle an Hochschulen e.V. plugin catalogue in 2022. Credits ------- -This Moodle plugin is only a simple wrapper for the Redis Stats management GUI by Helmut K. C. Tessarek. -Helmut owns all copyrights for Redis Stats and maintains this tool on https://github.com/tessus/redis-stats. +This Moodle plugin is only a simple wrapper for the Valkey Stats management GUI by Helmut K. C. Tessarek. +Helmut owns all copyrights for Valkey Stats and maintains this tool on https://github.com/tessus/valkey-stats. diff --git a/UPGRADE.md b/UPGRADE.md index 3ba4238..8975e50 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -14,7 +14,7 @@ General Upstream changes ---------------- -* This plugin relies on the thiry-party Redis Stats management GUI tool which is located within the plugin directory. Every now and then, it should be checked if there is a new version which could be updated in the plugin. +* This plugin relies on the thiry-party Valkey Stats management GUI tool which is located within the plugin directory. Every now and then, it should be checked if there is a new version which could be updated in the plugin. Automated tests diff --git a/flushdb.php b/flushdb.php index ef69ffe..2c83e14 100644 --- a/flushdb.php +++ b/flushdb.php @@ -17,9 +17,9 @@ /** * Admin tool "Redis management" - Redis Stats Flush DB stub. * - * The Redis Stats code which we have placed into lib/redis-stats/redis-stats.php.inc + * The Valkey Stats code which we have placed into lib/valkey-stats/valkey-stats.php.inc * is calling a file called flushdb.php to flush the Redis DB. - * With this file, we provide a stub at the location where the Redis Stats code expect it to be and include the original file. + * With this file, we provide a stub at the location where the Valkey Stats code expect it to be and include the original file. * * @package tool_redis * @copyright 2020 Alexander Bias, Ulm University @@ -36,5 +36,5 @@ // Make sure that only admins flush the DB. require_capability('moodle/site:config', context_system::instance()); -// Include Redis Stats Flush DB. -require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/redis/lib/redis-stats/flushdb.php.inc'); +// Include Valkey Stats Flush DB. +require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/redis/lib/valkey-stats/flushdb.php.inc'); diff --git a/index.php b/index.php index b6ed4ad..15ac500 100644 --- a/index.php +++ b/index.php @@ -39,7 +39,7 @@ ob_start(); // Include Redis Stats. -require_once(__DIR__ . '/lib/redis-stats/redis-stats.php.inc'); +require_once(__DIR__ . '/lib/valkey-stats/valkey-stats.php.inc'); // Get buffered content and finish buffering. $output = ob_get_contents(); diff --git a/lib/redis-stats/LICENSE b/lib/valkey-stats/LICENSE similarity index 100% rename from lib/redis-stats/LICENSE rename to lib/valkey-stats/LICENSE diff --git a/lib/redis-stats/config.php b/lib/valkey-stats/config.php similarity index 93% rename from lib/redis-stats/config.php rename to lib/valkey-stats/config.php index 90d2491..01229bd 100644 --- a/lib/redis-stats/config.php +++ b/lib/valkey-stats/config.php @@ -17,9 +17,9 @@ /** * Admin tool "Redis management" - Redis Stats configuration file * - * The Redis Stats code which we have placed into lib/redis-stats/redis-stats.php.inc + * The Valkey Stats code which we have placed into lib/valkey-stats/valkey-stats.php.inc * is looking for a file called config.php and includes this file. - * In this file, we can set the configuration of Redis Stats. + * In this file, we can set the configuration of Valkey Stats. * * @package tool_redis * @copyright 2020 Alexander Bias, Ulm University @@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die(); -// Get the Redis server(s) configuration from the MUC configuration and provide it in a way as Redis Stats expects it. +// Get the Redis server(s) configuration from the MUC configuration and provide it in a way as Valkey Stats expects it. // // Servers are defined as an array // [ Name, IP/Socket, Port, Password ] diff --git a/lib/redis-stats/flushdb.php.inc b/lib/valkey-stats/flushdb.php.inc similarity index 73% rename from lib/redis-stats/flushdb.php.inc rename to lib/valkey-stats/flushdb.php.inc index c21fea8..2573ebb 100644 --- a/lib/redis-stats/flushdb.php.inc +++ b/lib/valkey-stats/flushdb.php.inc @@ -1,13 +1,13 @@ ".PHP_EOL; + var_dump($var); + if ($pre) echo "".PHP_EOL; + } +} + +// Talk to server $error = null; $fp = @fsockopen($servers[$server][1], $servers[$server][2], $errno, $errstr, 30); @@ -79,8 +90,9 @@ if (!$fp) } else { - $redisCommand = ''; - $ASYNC = ''; + $vkCommand = ''; + $ASYNC = ''; + $numCmds = 0; isset($servers[$server][3]) ? $pwdEntry = $servers[$server][3] : $pwdEntry = null; if (!is_null($pwdEntry) && !empty($pwdEntry)) @@ -97,7 +109,8 @@ else { $credentials = $pwdEntry; } - $redisCommand = "$AUTH $credentials\r\n"; + $vkCommand = "$AUTH $credentials\r\n"; + $numCmds++; } if ($async) // we want async flush { @@ -105,14 +118,16 @@ else } if ($db != -1) // one specific database { - $redisCommand .= "SELECT $db\r\n$FLUSHDB$ASYNC\r\nQUIT\r\n"; + $vkCommand .= "SELECT $db\r\n$FLUSHDB$ASYNC\r\nQUIT\r\n"; + $numCmds += 3; } else // entire instance { - $redisCommand .= "$FLUSHALL$ASYNC\r\nQUIT\r\n"; + $vkCommand .= "$FLUSHALL$ASYNC\r\nQUIT\r\n"; + $numCmds += 2; } - fwrite($fp, $redisCommand); + fwrite($fp, $vkCommand); while (!feof($fp)) { $info[] = trim(fgets($fp)); @@ -120,25 +135,19 @@ else fclose($fp); } -if (array_unique($info) === array('+OK')) -{ -/* KIZ MODIFICATION START - REASON: Redis Stats must not use any custom session handling. */ -/* ORIGINAL START - $_SESSION['id'] = ''; - ORIGINAL END */ - echo "Success"; -} -else +for ($i = 0; $i < $numCmds; $i++) { - if (DEBUG === true) - { - var_dump($redisCommand); - var_dump($info); - } - foreach ($info as $v) + if ($info[$i] != '+OK') { - if ($v != '+OK') - die($v); + debug($vkCommand); + debug($info); + die($info[$i]); } } + +/* MAH MODIFICATION START + REASON: Valkey Stats must not use any custom session handling. */ +/* ORIGINAL START +$_SESSION['id'] = ''; + ORIGINAL END */ + echo "Success"; diff --git a/lib/redis-stats/redis-stats.php.inc b/lib/valkey-stats/valkey-stats.php.inc similarity index 88% rename from lib/redis-stats/redis-stats.php.inc rename to lib/valkey-stats/valkey-stats.php.inc index b287996..c7e5b14 100644 --- a/lib/redis-stats/redis-stats.php.inc +++ b/lib/valkey-stats/valkey-stats.php.inc @@ -1,9 +1,9 @@ (int) ($secs / 31556926) % 12, - ' week' => (int) ($secs / 604800) % 52, - ' day' => (int) ($secs / 86400) % 7, - ' hour' => (int) ($secs / 3600) % 24, - ' minute' => (int) ($secs / 60) % 60, + ' year' => floor($secs / 31556926) % 12, + ' week' => floor($secs / 604800) % 52, + ' day' => floor($secs / 86400) % 7, + ' hour' => floor($secs / 3600) % 24, + ' minute' => floor($secs / 60) % 60, ' second' => $secs % 60, ]; @@ -197,8 +197,8 @@ function debug($var, $pre = true) - -Redis Stats + +Valkey Stats