Drupal 8 Redis

broken image


  1. Drupal 8 Redis Session
  2. Drupal 8 Redis Settings.php
  3. Drupal 8 Redis
  4. Drupal 8 Redistributable
  5. Drupal 8 Redis Module

Configure Drupal settings. To get Redis works with your Drupal site, you need to modify your site's settings.php according to below. Use redis for container cache. The container cache is used to load the container definition itself, and thus any configuration stored in the container itself is not available yet. Implementing Redis as a Caching Backend for Drupal 8. Drupal 8 is packed with features designed to optimize performance (e.g. However, for busier sites, it may be desirable, or even necessary, to get a little bit more horsepower. One of the easiest ways to do this is to use a 'caching backend', such as Redis, a very popular and reliable NoSQL platform.

There are many ways to speed up your website and reduce load on the web server by using a cache. I reviewed different types of caching in the previous article and in this series I'll try to show you how to get the best performance with minimum configuring.

  1. Drupal 8 and Redis, part 1: NGINX serve content directly out of a Redis cache

The idea has been around for a while — data is stored in the memory, in Memcached or Redis (a fast key-value store), so that Nginx can get data directly from Redis without sending requests to PHP.

This is essentially how it works:

Nginx gets a page request and tries to get data from Redis first. If the Redis cache doesn't contain the page, the request is passed to PHP (Drupal).

Now let's see how to implement this.

Nginx

First, we need to add the HTTP Redis module to NGINX, so that it can interact with Redis. You can learn more about it in our article How to compile dynamic modules for NGINX (HTTP Redis as an example).

Drupal

There is another option with more functionality, Redis2, but we only need to read data, so HTTP Redis will suffice.

Drupal and Redis

Drupal 8 Redis Session

Then we install Redis on the web server and use it to store cache for Drupal (with the help of a Drupal module that you can find here).

Let's look at the records. We'll be using Keylord as a GUI for Redis:

Drupal 8 redis vs memcached

Keys are on the left, values are on the right. Records related to cached pages — the type of records we want to fetch — will have this in their keys:

And here is an example of a full key:

Drupal 8 redis settings.php

The value of the Data field:

The page is stored as a serialized Response object and Nginx can't read it.

Redis Page Cache

Ultimate cron drupal 8 custom. To enable Nginx to read these pages, we will create separate records in Redis to store HTML pages.

Then, Redis will have two types of records:

Drupal 8 Redis Settings.php

  1. Standard Drupal cache;
  2. Records with HTML pages as values. Let's call them Redis Page Cache.

Drupal 8 Redis

There are at least two approaches to storing pages in a separate cache (Redis Page Cache):

  1. Set a handler for one of the events that are triggered when Drupal sends a page back

Drupal 8 Redistributable

I chose the second option and the TERMINATE event. Tomcat 7 ssl.

Settings.php

There is another option with more functionality, Redis2, but we only need to read data, so HTTP Redis will suffice.

Drupal and Redis

Drupal 8 Redis Session

Then we install Redis on the web server and use it to store cache for Drupal (with the help of a Drupal module that you can find here).

Let's look at the records. We'll be using Keylord as a GUI for Redis:

Keys are on the left, values are on the right. Records related to cached pages — the type of records we want to fetch — will have this in their keys:

And here is an example of a full key:

The value of the Data field:

The page is stored as a serialized Response object and Nginx can't read it.

Redis Page Cache

Ultimate cron drupal 8 custom. To enable Nginx to read these pages, we will create separate records in Redis to store HTML pages.

Then, Redis will have two types of records:

Drupal 8 Redis Settings.php

  1. Standard Drupal cache;
  2. Records with HTML pages as values. Let's call them Redis Page Cache.

Drupal 8 Redis

There are at least two approaches to storing pages in a separate cache (Redis Page Cache):

  1. Set a handler for one of the events that are triggered when Drupal sends a page back

Drupal 8 Redistributable

I chose the second option and the TERMINATE event. Tomcat 7 ssl.

Related links:
The HttpKernel Component
The Drupal 8 render pipeline

So, we use Redis in two capacities: as the standard Drupal cache and as an external cache for pages.

Drupal 8 Redis Module

For Redis Page Cache we will use the following keys: rpcache:url. An example record:





broken image