Show
Setup Requirements
To test the Redis cluster with other features that have been provided by the existing system, such as TLS/SSL, Auth Password, please follow the instructions on Usage section at https://github.com/meirzamoodle/middleware-tutorials-redis-cluster-tls/tree/main#usage
Since there is a slight change to the single Redis unit testing, we need to install a single Redis on local machine and ensure it's running at 127.0.0.1:6379. Refer to this page on how to install Redis https://redis.io/docs/install/install-redis/ .
Ensure your machine has the PHP-Redis extension by checking on the Info PHP page. There are a lot of ways to check the PHP Info Page. Moodle has provided it on the Site Admin > Server > PHP info.
If it has not been installed, you can install it by running the below command:
pecl install redis
Please visit https://developer.redis.com/develop/php/ for detailed information on how to do the installation.
The testing will involve Redis CLI using a shell/terminal to trigger a failure on one of the nodes.
During the unit testing, if enabled, please disable the Xdebug on your PHP CLI config.
Steps to run the PHPUnit for Redis cluster session
Open config.php and add the below codes:
define(
'TEST_SESSION_REDIS_HOSTCLUSTER' ,
'172.23.0.11,172.23.0.12,172.23.0.13,172.23.0.14,172.23.0.15,172.23.0.16'
);
define(
'TEST_SESSION_REDIS_ENCRYPTCLUSTER' ,
[ 'verify_peer' => false , 'verify_peer_name' => false ],
);
define(
'TEST_SESSION_REDIS_AUTHCLUSTER' ,
'foobared'
);
Make sure all the tests in lib/tests/session_redis_cluster_test.php are passed.
Steps to run the PHPUnit for Redis cluster cache store
Open config.php and add the below codes:
define(
'TEST_CACHESTORE_REDIS_SERVERSCLUSTER' ,
'172.23.0.11,172.23.0.12,172.23.0.13,172.23.0.14,172.23.0.15,172.23.0.16'
);
define(
'TEST_CACHESTORE_REDIS_ENCRYPTCLUSTER' ,
true
);
define(
'TEST_CACHESTORE_REDIS_AUTHCLUSTER' ,
'foobared'
);
Make sure all the tests in cache/stores/redis/tests/cachestore_cluster_redis_test.php are passed.
Steps to run the PHPUnit for single Redis session
Open config.php and add the below codes:
define(
'TEST_SESSION_REDIS_HOST' ,
'127.0.0.1'
);
Make sure all the tests in lib/tests/session_redis_test.php are passed.
Redis Testing Performance and failover testing
Run the docker compose command to activate the Redis Cluster (Setup requirements number one)
Log in as admin
Navigate to Site Admin > Plugins > Caching > Cache Stores > Redis
Tick the Cluster Mode checkbox
Specify the Test server with the below IP addresses
172.23.0.11
172.23.0.12
172.23.0.13
172.23.0.14
172.23.0.15
172.23.0.16
Tick the Use TLS encryption checkbox
Specify the path of the CA file where you are cloning the Redis Cluster docker image. For instance, if you are cloning at " /home/moodle/middleware-tutorials-redis-cluster-tls ", the file path for CA is " /home/moodle/middleware-tutorials-redis-cluster-tls/tls/ca.crt ".
Specify the Test server password with foobared
Click the Save canges button.
Verify that there is a success notification with the words "Changes saved".
Navigate to Site Admin > Plugins > Caching > Test performance
Select whatever number of requests you want to test with
Verify that there is no error warning
Verify that on the Redis row, the result column has "tested" label.
Now we will do the failover testing. Open your shell/terminal.
Run the below command:
redis-cli -a foobared -h 172.23 . 0.11 --tls --cacert /home/moodle/middleware-tutorials-redis-cluster-tls/tls/ca.crt
In the Redis CLI prompt, run the below command:
debug segfault
Verify that you will see the message "Error: Server closed the connection". That means that the node with IP address 172.23.0.11 is down.
Return to the browser. Navigate to Site Admin > Plugins > Caching > Test performance.
If you see an error warning like the below messages:
> The Redis Cluster is down (CLUSTERDOWN)
> Timed out attempting to find data in the correct node!
Please keep reload the Test performance page until those messages disappear, my machine needs 20-30 seconds to get normal, the time can vary depending on the machine. After some time verify that there is no error warning.
Cache Store Testing
Run the docker compose command to activate the Redis Cluster (Setup requirements number one)
Log in as admin
Navigate to Site Admin > Plugins > Caching > Configuration
Click the Add Instance link in the Redis row
Specify the Store name with Redis cluster store
Tick the Cluster Mode checkbox
Specify the servers with the below IP addresses
172.23.0.11
172.23.0.12
172.23.0.13
172.23.0.14
172.23.0.15
172.23.0.16
Tick the Use TLS encryption checkbox
Specify the path of the CA file where you are cloning the Redis Cluster docker image. For instance, if you are cloning at " /home/moodle/middleware-tutorials-redis-cluster-tls ", the file path for CA is " /home/moodle/middleware-tutorials-redis-cluster-tls/tls/ca.crt ".
Specify the password with foobared
Click the Save canges button.
Verify that there is a success notification "Successfully added a new Redis store. "
Verify that in the Redis stores column, there is a value 1
Go to the bottom of the page
Click "Edit mappings" link
For the Application and Session dropdowns, select "Redis cluster store"
Click the Save changes button.
Verify that there is no error warning
At the Configured store instances, click the Purge link at the Redis cluster store row
Verify that there is a successfull notification "Successfully purged the "Redis cluster store" store. Purge again"
Session Testing
Run the docker compose command to activate the Redis Cluster (Setup requirements number one)
Edit the config.php and add the below lines:
$CFG->session_handler_class = '\core\session\redis' ;
$CFG->session_redis_host = '172.23.0.11,172.23.0.12,172.23.0.13,172.23.0.14,172.23.0.15,172.23.0.16' ;
$CFG->session_redis_auth = 'foobared' ;
$CFG->session_redis_encrypt = [ 'cafile' => '/home/moodle/middleware-tutorials-redis-cluster-tls/tls/ca.crt' ];
Return to the browser.
Reload the web page.
Verify that there is no error warning.