Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-69668

Add Redis Sentinel support to Moodle core

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 3.9.1
    • Caching, Libraries
    • None
    • MOODLE_39_STABLE
    • Hide

      Configure the required extensions before applying the patch

      1. Install Redis and the Redis PHP extension and configure it (on ubuntu it is redis-sentinel and redis-server, making sure that the bind address is 127.0.0.1).
      2. Check that redis sentinel and redis server are working (redis-cli for example)
      3. Restart your web server.

      Cache

      Configure the improved cache store

      1. Browse to Admin > Plugins > Caching > Stores > Redis
      2. Set a Redis Sentinel test server (127.0.0.1 default port being 26379)
      3. Check the "Is Test server a Redis Sentinel"
      4. Browse to Admin > Plugins > Caching > Test performance
      5. Make sure that Redis is being tested.
      6. Browse to Admin > Plugins > Caching > Configuration
      7. Create a Redis instance
      8. Map it to the string and config caches
      9. Browse the site and make sure everything is OK.

      Test the new cache store via PHPUnit

      To ensure Redis is working in the testing space

      1. in config.php, set:

        define('TEST_CACHESTORE_REDIS_SENTINEL_TESTSERVERS', '127.0.0.1');
        define('TEST_CACHESTORE_REDIS_SENTINEL_MASTERNAME', 'mymaster'); define('TEST_CACHESTORE_REDIS_IS_SENTINEL',true);
        

      2. Verify Redis testing is passing by itself with (.)'s and aren't skipped (see redis_sentinel_test.php):

        vendor/bin/phpunit cache/stores/redis/tests/redis_sentinel_test.php
        

      3. Add the following to config.php to use redis as the default application store for testing;

        define('TEST_CACHE_USING_APPLICATION_STORE' , 'redis');
        

      4. Run PHPUnit to verify that all the tests pass with a different store set.

        vendor/bin/phpunit

      Session

      Configure the new session handler

      1. In config.php, set:

        $CFG->session_handler_class = '\core\session\redis_sentinel';
        $CFG->session_redis_sentinel_host = '127.0.0.1';
        $CFG->session_redis_sentinel_port = 26379;
        $CFG->session_redis_master_name = 'mymaster';
        $CFG->session_redis_database = 0; // Optional, default is db 0.
        $CFG->session_redis_auth = ''; // Optional, default is don't set one.
        $CFG->session_redis_prefix = 'sess'; // Optional, default is don't set one.
        $CFG->session_redis_acquire_lock_timeout = 120;

      2. Check that you can login

      Test the new session handler via PHPUnit

      1. in config.php, set:

        define('TEST_CACHESTORE_REDIS_SENTINEL_TESTSERVERS','127.0.0.1'); 
        define('TEST_CACHESTORE_REDIS_TESTSERVERS','127.0.0.1'); define('TEST_CACHESTORE_REDIS_SENTINEL_MASTERNAME','mymaster');
        

      2. Verify Redis testing is passing by itself with (.)'s and aren't skipped (see redis_sentinel_test.php):

        vendor/bin/phpunit  lib/tests/session_redis_sentinel_test.php

      Show
      Configure the required extensions before applying the patch Install Redis and the Redis PHP extension and configure it (on ubuntu it is redis-sentinel and redis-server, making sure that the bind address is 127.0.0.1). Check that redis sentinel and redis server are working (redis-cli for example) Restart your web server. Cache Configure the improved cache store Browse to Admin > Plugins > Caching > Stores > Redis Set a Redis Sentinel test server (127.0.0.1 default port being 26379) Check the "Is Test server a Redis Sentinel" Browse to Admin > Plugins > Caching > Test performance Make sure that Redis is being tested. Browse to Admin > Plugins > Caching > Configuration Create a Redis instance Map it to the string and config caches Browse the site and make sure everything is OK. Test the new cache store via PHPUnit To ensure Redis is working in the testing space in config.php , set: define('TEST_CACHESTORE_REDIS_SENTINEL_TESTSERVERS', '127.0.0.1'); define('TEST_CACHESTORE_REDIS_SENTINEL_MASTERNAME', 'mymaster'); define('TEST_CACHESTORE_REDIS_IS_SENTINEL',true); Verify Redis testing is passing by itself with (.)'s and aren't skipped (see redis_sentinel_test.php ): vendor/bin/phpunit cache/stores/redis/tests/redis_sentinel_test.php Add the following to config.php to use redis as the default application store for testing; define('TEST_CACHE_USING_APPLICATION_STORE' , 'redis'); Run PHPUnit to verify that all the tests pass with a different store set. vendor/bin/phpunit Session Configure the new session handler In config.php , set: $CFG->session_handler_class = '\core\session\redis_sentinel' ; $CFG->session_redis_sentinel_host = '127.0.0.1' ; $CFG->session_redis_sentinel_port = 26379 ; $CFG->session_redis_master_name = 'mymaster' ; $CFG->session_redis_database = 0 ; // Optional, default is db 0. $CFG->session_redis_auth = '' ; // Optional, default is don't set one. $CFG->session_redis_prefix = 'sess' ; // Optional, default is don't set one. $CFG->session_redis_acquire_lock_timeout = 120 ; Check that you can login Test the new session handler via PHPUnit in config.php , set: define('TEST_CACHESTORE_REDIS_SENTINEL_TESTSERVERS','127.0.0.1'); define('TEST_CACHESTORE_REDIS_TESTSERVERS','127.0.0.1'); define('TEST_CACHESTORE_REDIS_SENTINEL_MASTERNAME','mymaster'); Verify Redis testing is passing by itself with (.)'s and aren't skipped (see redis_sentinel_test.php ): vendor/bin/phpunit lib/tests/session_redis_sentinel_test.php

      Following up MDL-48468 and using the RedisSentinel available in php-redis 5.2 (https://github.com/phpredis/phpredis/blob/develop/Changelog.md), it is now possible to connect to Redis Sentinel for Redis Clusters.

      The idea here is to do minimal changes to the core so to enable this:

      • In the session management 
      • In the cache 

      The way it has been implemented is strongly linked to the availability of the RedisSentinel function but I guess it can be done though normal redis connector as the protocol for Sentinel is just using normal redis connector. 

      The only thing that is not supported yet is password/ auth for the sentinel.

      Cache

      Process for testing cache:

      1. Install Redis and the Redis PHP extension and configure it (on ubuntu it is redis-sentinel and redis-server, making sure that the bind address is 127.0.0.1).
      2. Check that redis sentinel and redis server are working (redis-cli for example)
      3. Restart your web server.
      4. Browse to Admin > Plugins > Caching > Stores > Redis
      5. Set a Redis Sentinel test server (127.0.0.1 default port being 26379)
      6. Check the "Is Test server a Redis Sentinel"
      7. Browse to Admin > Plugins > Caching > Test performance
      8. Make sure that Redis is being tested.
      9. Browse to Admin > Plugins > Caching > Configuration
      10. Create a Redis instance
      11. Map it to the string and config caches
      12. Browse the site and make sure everything is OK.

      Now same process as testing redis:

      To ensure Redis is working in the testing space

      1. in config.php, set:

       

      define('TEST_CACHESTORE_REDIS_SENTINEL_TESTSERVERS', '127.0.0.1');
      define('TEST_CACHESTORE_REDIS_SENTINEL_MASTERNAME', 'mymaster'); define('TEST_CACHESTORE_REDIS_IS_SENTINEL',true);
      

      Verify Redis testing is passing by itself with (.)'s and aren't skipped (see redis_sentinel_test.php).

       

      vendor/bin/phpunit cache/stores/redis/tests/redis_sentinel_test.php

      Add the following to config.php to use redis as the default application store for testing;

       

      define('TEST_CACHE_USING_APPLICATION_STORE' , 'redis');
      Run PHPUnit to verify that all the tests pass with a different store set.

      vendor/bin/phpunit

      Session

      The session management is slightly different:

      1. In config.php, set:

      $CFG->session_handler_class = '\core\session\redis_sentinel';
      $CFG->session_redis_sentinel_host = '127.0.0.1';
      $CFG->session_redis_sentinel_port = 26379;
      $CFG->session_redis_master_name = 'mymaster';
      $CFG->session_redis_database = 0; // Optional, default is db 0.
      $CFG->session_redis_auth = ''; // Optional, default is don't set one.
      $CFG->session_redis_prefix = 'sess'; // Optional, default is don't set one.
      $CFG->session_redis_acquire_lock_timeout = 120;

      1. Check that you can login

      Now same process as testing redis sentinel cache:

      To ensure Redis is working in the testing space

      1. in config.php, set: 

      define('TEST_CACHESTORE_REDIS_SENTINEL_TESTSERVERS','127.0.0.1'); 
      define('TEST_CACHESTORE_REDIS_TESTSERVERS','127.0.0.1'); define('TEST_CACHESTORE_REDIS_SENTINEL_MASTERNAME','mymaster');
      

      Verify Redis testing is passing by itself with (.)'s and aren't skipped (see redis_sentinel_test.php).

       

      vendor/bin/phpunit  lib/tests/session_redis_sentinel_test.php

            Unassigned Unassigned
            lmdavid Laurent DAVID
            Votes:
            7 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.