Integration of Redis cache with Drupal 8

Integrating Redis cache with Drupal instance

Installing of PHPRedis Library

  • First you need to install PHPRedis Library for using redis cache with Drupal instance.
  • In case of Fedora OS, use the following yum command for installing PHPRedis Library
    • sudo yum install php-pecl-redis
  • In case of Ubuntu OS, use the following apt-get command 
    • sudo apt-get install php-redis
Installing PHP Redis

Installing Redis tools:

  • Download the Stable version of Redis package from Redis.io and untar it as below.
    • tar -xvfz redis-stable.tar.gz
  • Switch to redis folder
    • cd redis-stable
  • Check whether GCC/CC compiler is installed in your system,if not, install it
    • yum -y install gcc
  • Create a make file for the redis dependencies i.e,. for the following folders hiredis,jemalloc,linenoise and lua.
  • You can find these directories under redis-stable/deps/ directory.
    • make hiredis lua jemalloc linenoise
Creating execution file for php redis dependencies
  • Then, switch to redis-stable directory and create a make file for the redis
    • make
Running make execution under PHP Redis
  • Make execution will ends as below  
End screen of Make execution under PHP Redis directory
  • For confirming, the proper installation of Redis, type
    • make test
Validating the make execution using make test command
  • Make test will ends as below
End screen of make test validation
  • After installing you will find, set of execution files in src/ directory namely redis-cli,redis-server,etc.,
  • Standard way of using redis-cli and redis-server is copying those two files to /usr/local/bin, so that it can be accessed from any location.
    • sudo cp -r redis-cli redis-server /usr/local/bin/

Working with Redis:

  • First start the Redis server by executing below command
    • redis-server
Starting Redis server through command line
  • Open a new tab,type the below command for interacting with Redis
    • redis-cli
  • You can test Redis by setting and getting key-value pair.
    • Set Key-Value:
      • redis127.0.0.1:6379>set <key> <value>
    • For example: redis127.0.0.1:6379>set dolby 5.1
    • Get Value:
      • redis127.0.0.1:6379>get <key>
    • For example: redis127.0.0.1:6379>get dolby 5.1
    • Listing all the keys
      • redis127.0.0.1:6379>keys *

Integrating Redis cache with Drupal Instance:

  • Download and Install Redis Module from http://drupal.org.
  • Include the following lines code in settings.php of your instance.
    • $settings['redis.connection']['interface'] = 'PhpRedis'; // Can be "Predis".
    • $settings['redis.connection']['host']      = 'localhost';  // Your Redis instance hostname.
    • $settings['cache']['default'] = 'cache.backend.redis';

Checking the Redis cache integration with your Drupal Instance:

  • Start the redis server.
  • Use redis command line interface $redis-cli
  • If redis cache integrated successfully your instance,then on executing keys *, you will be able to see list of key-value pair as below.
Validating redis configuration using Redis client command



Kindly Subsribe to Things to know -Mr Ko & Acquia Pantheon Drupal Blog.
To get latest updates and solutions for the errors you facing.