Redis cache store
The Redis cache store is one of the best options to handle session and application cache as it supports: data guarantee, locking, key awareness. (and also can be used for user's sessions caching in the config.php file). Unfortunately due to the data types it supports and the data involved, it isn't fully compatible with the request cache, and so we'll only be configuring it for the Application and Session caches in this document. That isn't to say you couldn't have parts of the request cache using Redis, you would just need to manually set those cached objects to use Redis instead (and there are quite a few of them!).
Before Redis is available as a cache store, you will need to install Redis service (daemon) on your Moodle server, locally in case of a single Moodle app node architecture or externally if you are using a cluster of Moodle nodes. only then, you can configure Redis as an application or session level cache store.
If you are configuring a cluster of Moodle servers/nodes, the Redis service (daemon) should be installed on an external server and all Moodle nodes (servers/instances) should point to that external Redis, so that all the user's cached data (namely Session) is available when the user is using/connected to any of the Moodle nodes. An external Redis (NoSQL) service can be installed on the main SQL server alongside the MySQL/MariaDB service, just make sure you have enough memory allocated on that server for both services.
A good practice is to give the Redis cache store prefix a proper short name and not leave it empty, as later on, it might conflict with user's session Redis cache you might choose to use, or other Moodle instances that will be installed on the same server. for example "my-school-name_cs_", where you replace "my-school-name" with your short school name. (and if you are also using a user's session store on the config.php file, you might like to prefix it with "my-school-name_us_")
When using a cluster setup with several Moodle instances on each node that belong to different Schools/Institutes/clients, make sure that you use the same Prefix for all Moodle instances that are on different nodes and are of the same School/Institute/Client.
Moodle also supports connecting to Redis Cluster, which is Redis’s built-in mechanism for distributing data across multiple Redis nodes. Redis Cluster provides horizontal scaling, automatic failover, and high availability, making it ideal for large or high-traffic Moodle deployments, or sites using cloud-managed Redis services. Using a Redis Cluster does not change the user-facing experience, it only enhances performance and reliability in distributed Moodle architectures.
Installing Redis server
There are plenty of guides on the internet on how to install Redis, so we won't repeat them here. Since Redis is a listening service, once it's installed it'll be ready to use (and should already be running) and ready to receive requests from Moodle, with no further configuration needed. With that said however, it's still wise to have a look through the configuration options and decide what is best for you and your setup - the DigitalOcean guide is a good place to start for adjusting these settings, as they're basically all in the redis.conf file.
- DigitalOcean's How To Install and Secure Redis on Ubuntu 22.04
- Session_handling#Redis_session_driver and How to Set Up a Redis Server as a Session Handler for PHP
- Install Redis 5 via IUS CentOS 7 repository.
- Redis Windows Port - zkteco-home/redis-windows on GitHub
Installing Redis php driver
- For CentOS, you can use either Remi or IUS repositories, and install the php71u-pecl-redis driver.
- Redis php-fpm 7 driver on Ubuntu 14.04
- Windows PHP extensions including DLLs for Windows. Check your PHP version, CPU (64bit or x86) and thread-safe value (see Site Admin > Server > PHP Info) to get the right version; add DLL file to ext directory, add 'extension=php_redis.dll' entry to php.ini and restart your web server.
Configuring Redis in Moodle
- Navigate to Site admin > Plugins > Caching > Configuration.
- When installed, you should see a green tick next to "Redis" under "Installed cache stores" and a link to add an instance.
- Click "Add instance".
- Give your Redis instance a name, like "Redis1".
- Tick the Cluster mode checkbox if you want to use the Redis Cluster. If the checkbox is disabled, it means your PHP Redis extension does not support the Cluster feature.
- Set the IP:port for the Redis server. If it is on the same machine, the default will be 127.0.0.1:6379. If cluster mode is enabled, specify servers separated by a new line, for example:
172.23.0.11
172.23.0.12
172.23.0.13 - Specify the file path to the Certificate Authority (CA) certificate to verify the TLS/SSL connection to a Redis server, confirming the server's authenticity. Leave it blank if you prefer not to use it.
- Enter the password for your Redis server. Leave it blank if you prefer not to use it.
- Enter a short, unique prefix that will be added to all Redis keys created by this Moodle site. Leave it blank if you prefer not to use it.
- Choose the method Moodle will use to encode cache data before storing it in Redis. If available, igbinary is recommended because it is faster and uses less memory than the default PHP serializer.If your system does not have igbinary installed, Moodle will fall back to the standard PHP serializer.
- Select whether Moodle should compress cache data before storing it in Redis.
- Set the maximum number of seconds Moodle will wait for a Redis node to accept a connection. If the Redis server is busy, overloaded, or unreachable, Moodle will stop waiting after this timeout and report a connection failure. Default is 3 seconds.
- Click the Save Changes button, and the new instance should appear under "Configured store instances" with a "Ready" tick.
- Under "Stores used when no mapping is present" click Edit mappings". Set "Redis1" (or the name used earlier) for the "Application" and "Session" caches. Note that Redis won't appear under the "Request" Cache section, since it isn't fully compatible with all of the different parts of the request cache. (Refer to the Caching page to better understand how the Moodle Universal Cache works).
- After saving this, you should see Redis as the cache for most cache stores, and should hopefully see a performance boost almost immediately.
- Next Step: Celebrate!
See also
- Monitor Redis stats (a php one page app)
- MDL-48468 : Add a Redis cache store to Moodle core
- Redis lock : https://github.com/open-lms-open-source/moodle-local_redislock (get it into core: https://tracker.moodle.org/browse/MDL-67022)
- Redis.io

