Skip to content

Commit c2ca7ca

Browse files
committed
Replace Redis Stats GUI with the newer Valkey Stats GUI
1 parent 59ca8fe commit c2ca7ca

File tree

11 files changed

+119
-90
lines changed

11 files changed

+119
-90
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ moodle-tool_redis
44
Changes
55
-------
66

7+
### Unreleased
8+
9+
* 2024-10-29 - Replace Redis Stats GUI with the newer Valkey Stats GUI
10+
711
### v4.3-r3
812

913
* 2024-08-21 - Replace deprecated print_error() with moodle_exception.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Motivation for this plugin
1717

1818
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.
1919

20-
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.
20+
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.
2121

22-
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.
22+
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.
2323

2424

2525
Installation
@@ -171,5 +171,5 @@ It was contributed to the Moodle an Hochschulen e.V. plugin catalogue in 2022.
171171
Credits
172172
-------
173173

174-
This Moodle plugin is only a simple wrapper for the Redis Stats management GUI by Helmut K. C. Tessarek.
175-
Helmut owns all copyrights for Redis Stats and maintains this tool on https://github.com/tessus/redis-stats.
174+
This Moodle plugin is only a simple wrapper for the Valkey Stats management GUI by Helmut K. C. Tessarek.
175+
Helmut owns all copyrights for Valkey Stats and maintains this tool on https://github.com/tessus/valkey-stats.

UPGRADE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ General
1414
Upstream changes
1515
----------------
1616

17-
* 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.
17+
* 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.
1818

1919

2020
Automated tests

flushdb.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
/**
1818
* Admin tool "Redis management" - Redis Stats Flush DB stub.
1919
*
20-
* The Redis Stats code which we have placed into lib/redis-stats/redis-stats.php.inc
20+
* The Valkey Stats code which we have placed into lib/valkey-stats/valkey-stats.php.inc
2121
* is calling a file called flushdb.php to flush the Redis DB.
22-
* With this file, we provide a stub at the location where the Redis Stats code expect it to be and include the original file.
22+
* With this file, we provide a stub at the location where the Valkey Stats code expect it to be and include the original file.
2323
*
2424
* @package tool_redis
2525
* @copyright 2020 Alexander Bias, Ulm University <alexander.bias@uni-ulm.de>
@@ -36,5 +36,5 @@
3636
// Make sure that only admins flush the DB.
3737
require_capability('moodle/site:config', context_system::instance());
3838

39-
// Include Redis Stats Flush DB.
40-
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/redis/lib/redis-stats/flushdb.php.inc');
39+
// Include Valkey Stats Flush DB.
40+
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/redis/lib/valkey-stats/flushdb.php.inc');

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
ob_start();
4040

4141
// Include Redis Stats.
42-
require_once(__DIR__ . '/lib/redis-stats/redis-stats.php.inc');
42+
require_once(__DIR__ . '/lib/valkey-stats/valkey-stats.php.inc');
4343

4444
// Get buffered content and finish buffering.
4545
$output = ob_get_contents();
File renamed without changes.

lib/redis-stats/config.php renamed to lib/valkey-stats/config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
/**
1818
* Admin tool "Redis management" - Redis Stats configuration file
1919
*
20-
* The Redis Stats code which we have placed into lib/redis-stats/redis-stats.php.inc
20+
* The Valkey Stats code which we have placed into lib/valkey-stats/valkey-stats.php.inc
2121
* is looking for a file called config.php and includes this file.
22-
* In this file, we can set the configuration of Redis Stats.
22+
* In this file, we can set the configuration of Valkey Stats.
2323
*
2424
* @package tool_redis
2525
* @copyright 2020 Alexander Bias, Ulm University <alexander.bias@uni-ulm.de>
@@ -28,7 +28,7 @@
2828

2929
defined('MOODLE_INTERNAL') || die();
3030

31-
// Get the Redis server(s) configuration from the MUC configuration and provide it in a way as Redis Stats expects it.
31+
// Get the Redis server(s) configuration from the MUC configuration and provide it in a way as Valkey Stats expects it.
3232
//
3333
// Servers are defined as an array
3434
// [ Name, IP/Socket, Port, Password ]

lib/redis-stats/flushdb.php.inc renamed to lib/valkey-stats/flushdb.php.inc

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
/* KIZ MODIFICATION START
4-
REASON: Redis Stats must not use any custom session handling. */
3+
/* MAH MODIFICATION START
4+
REASON: Valkey Stats must not use any custom session handling. */
55
require(__DIR__ . '/../../../../../config.php');
66
if (!isset($_GET['id']) || isset($_GET['id']) && $_GET['id'] != sesskey())
77
{
88
die("Invalid request.");
99
}
10-
/* KIZ MODIFICATION END */
10+
/* MAH MODIFICATION END */
1111
/* ORIGINAL START
1212
session_start();
1313
@@ -66,7 +66,18 @@ if (isset($command[$serverName]['AUTH']) && !is_null($command[$serverName]['AUTH
6666
$AUTH = $command[$serverName]['AUTH'];
6767
}
6868

69-
// Talk to Redis server
69+
// Functions
70+
function debug($var, $pre = true)
71+
{
72+
if (DEBUG)
73+
{
74+
if ($pre) echo "<pre>".PHP_EOL;
75+
var_dump($var);
76+
if ($pre) echo "</pre>".PHP_EOL;
77+
}
78+
}
79+
80+
// Talk to server
7081
$error = null;
7182

7283
$fp = @fsockopen($servers[$server][1], $servers[$server][2], $errno, $errstr, 30);
@@ -79,8 +90,9 @@ if (!$fp)
7990
}
8091
else
8192
{
82-
$redisCommand = '';
83-
$ASYNC = '';
93+
$vkCommand = '';
94+
$ASYNC = '';
95+
$numCmds = 0;
8496

8597
isset($servers[$server][3]) ? $pwdEntry = $servers[$server][3] : $pwdEntry = null;
8698
if (!is_null($pwdEntry) && !empty($pwdEntry))
@@ -97,48 +109,45 @@ else
97109
{
98110
$credentials = $pwdEntry;
99111
}
100-
$redisCommand = "$AUTH $credentials\r\n";
112+
$vkCommand = "$AUTH $credentials\r\n";
113+
$numCmds++;
101114
}
102115
if ($async) // we want async flush
103116
{
104117
$ASYNC = ' ASYNC';
105118
}
106119
if ($db != -1) // one specific database
107120
{
108-
$redisCommand .= "SELECT $db\r\n$FLUSHDB$ASYNC\r\nQUIT\r\n";
121+
$vkCommand .= "SELECT $db\r\n$FLUSHDB$ASYNC\r\nQUIT\r\n";
122+
$numCmds += 3;
109123
}
110124
else // entire instance
111125
{
112-
$redisCommand .= "$FLUSHALL$ASYNC\r\nQUIT\r\n";
126+
$vkCommand .= "$FLUSHALL$ASYNC\r\nQUIT\r\n";
127+
$numCmds += 2;
113128
}
114129

115-
fwrite($fp, $redisCommand);
130+
fwrite($fp, $vkCommand);
116131
while (!feof($fp))
117132
{
118133
$info[] = trim(fgets($fp));
119134
}
120135
fclose($fp);
121136
}
122137

123-
if (array_unique($info) === array('+OK'))
124-
{
125-
/* KIZ MODIFICATION START
126-
REASON: Redis Stats must not use any custom session handling. */
127-
/* ORIGINAL START
128-
$_SESSION['id'] = '';
129-
ORIGINAL END */
130-
echo "Success";
131-
}
132-
else
138+
for ($i = 0; $i < $numCmds; $i++)
133139
{
134-
if (DEBUG === true)
135-
{
136-
var_dump($redisCommand);
137-
var_dump($info);
138-
}
139-
foreach ($info as $v)
140+
if ($info[$i] != '+OK')
140141
{
141-
if ($v != '+OK')
142-
die($v);
142+
debug($vkCommand);
143+
debug($info);
144+
die($info[$i]);
143145
}
144146
}
147+
148+
/* MAH MODIFICATION START
149+
REASON: Valkey Stats must not use any custom session handling. */
150+
/* ORIGINAL START
151+
$_SESSION['id'] = '';
152+
ORIGINAL END */
153+
echo "Success";

0 commit comments

Comments
 (0)