Redis is one of the several backend cache systems supported by Drupal.
The way Redis works is to cache the database queries on the first visit, and then serve the cached content to every other user that loads the same page, without querying the actual database.
Step 1: Installing Redis
Download, extract and compile Redis from root directory of the user:
tar xzf redis-6.2.6.tar.gz
The binaries that are now compiled are available in the src directory. Run Redis with:
You can interact with Redis using the built-in client:
src/redis-cliredis> set foo barOKredis> get foo"bar"
Step 2: Installing PHP Redis - A PHP Extension For Redis
To get things started, you will need to get your hands on the source code. The project is available on GitHub or you can easily grab it using wget (see below).
Once you have the source code downloaded and extracted cd to the directory (if you haven’t already) and you run:
sudo make install
phpize prepares the PHP extension for compiling. Think of it like a configure script for PHP stuff.
Make the install, do the compiling and copy the extension to the right place, respectively.
Now that the extension is installed, we need to configure PHP to use it. You can either add a line to your php.ini or simply create a new INI file just for Redis:
sudo echo "extension=redis.so" > /etc/php7(you specific PHP version)/conf.d/redis.ini
Once the file is created, all you will need to do is restart your web server. Once you’ve done so, do ahead and pull up phpinfo() and you should see a new section labelled “Redis”.
Step 3: Install the Redis module in Drupal
Download from Redis and enable this module.
Step 4: Configure Drupal 9 to use Redis!
Edit Drupal settings file: ./sites/default/settings.php and add these lines at the bottom of the file:
$settings['redis.connection']['interface'] = 'PhpRedis';$settings['cache']['default'] = 'cache.backend.redis';
Step 5: Clear your Drupal Cache:
Admin >> Configuration >> Performance >> Clear all caches and then visit the status report page: Admin >> Reports >> Status report.
You should see an entry for Redis in there which will tell you if you are connected or not:
And that's how you integrate Redis into Drupal 9!