Elasticache Redis for Drupal 6

OS => Ubuntu 11.10

Launch an elasticache node for Redis. I had to configure Drupal to use it instead of its default database cache. Redis Server integration for Drupal is provided by the Redis module(https://drupal.org/project/redis). As noted in the documentation, the Redis module can use two different PHP backends that interface with the Redis Server instance— Predis and PhpRedis. I opted for Predis, which is a PHP library that can be easily enabled in the Drupal settings.php file and doesn’t require changes to the server setup.


1.Download URL
2.Extract the code to to your /sites/all/modules/redis
3.Set the permissions with that of existing modules. (chown -R ubuntu.www-data /var/www/sites/all/modules/redis)
4.To finish you should enable the module or theme in the administration section of your site.

To start using Redis on my Drupal 6 site, I first had to enable the Cache Backport module. This module replaces the old Drupal 6 caching system with the much improved, modern cache system that debuted in Drupal 7. Enabling the backported cache module is different from enabling a normal Drupal module. Since the module actually comes from Drupal 7, it can’t be enabled on Drupal 6 through the admin interface. Rather, it must be enabled directly in the Drupal settings.php file. So after decompressing the Cache Backport module to the usual /sites/all/modules directory, I put the following lines at the bottom of my settings.php:

5.Enable Cache Backport Module
Download URL
Browse – admin/build/modules => Select Cache_Backport and Save Configuration.

#vim /var/www/sites/default/settings.php

##### Enable Cache Backport #####
$conf['cache_inc'] = 'sites/all/modules/cache_backport/cache.inc';
##### Enable different Cache Backport engines #####
$conf['cache_backends'][] = 'sites/all/modules/redis/redis.autoload.inc';
$conf['redis_client_interface'] = 'Predis';

NOTE: The above lines tell the Cache Backend to include Redis as one of its available engines and to communicate with the Redis Server via the Predis backend. But the current configuration still won’t cache data.

Drupal 6 dont have support for Redis thats why we use Cache Backport Module to use Redis cache. Drupal will communicate to Redis using this module.
NOTE : Predis PHP library is compatible with PHP 5.3 only

6.Installing Predis Library

#wget "https://github.com/nrk/predis/archive/v0.8.zip"
#unzip v0.8.zip
#cp ~/predis-0.8 sites/all/libraries/predis -rf

7.Finally edit & add the following lines to settings.php file to start caching.

#vim /var/www/sites/default/settings.php

$conf['redis_client_host'] = 'myredis.node.cache.amazonaws.com';
$conf['redis_client_port'] = 6379;
$conf['cache_prefix'] = 'mysite_redis';

# Handle these with Redis #
$conf['cache_default_class'] = 'Redis_Cache';
$conf['cache_class_cache_bootstrap'] = 'Redis_Cache';
$conf['cache_class_cache'] = 'Redis_Cache';
$conf['cache_class_cache_block'] = 'Redis_Cache';
$conf['cache_class_cache_content'] = 'Redis_Cache';
$conf['cache_class_cache_form'] = 'Redis_Cache';
$conf['cache_class_cache_menu'] = 'Redis_Cache';
$conf['cache_class_cache_page'] = 'Redis_Cache';
$conf['cache_class_cache_pathdst'] = 'Redis_Cache';
$conf['cache_class_cache_pathsrc'] = 'Redis_Cache';
$conf['cache_class_cache_rules'] = 'Redis_Cache';
$conf['cache_class_cache_users'] = 'Redis_Cache';
$conf['cache_class_cache_views'] = 'Redis_Cache';
$conf['cache_class_cache_views_data'] = 'Redis_Cache';

Above lines determine which data in Drupal is available for caching and which of those data are appropriate for storing in Redis.

Reference URLs
Use Cache_Prefix to enable single Redis caching for multiple drupal sites : http://drupalcode.org/project/redis.git/blob/refs/heads/7.x-2.x:/README.txt#l111

One thing I prefer about the Memcache integration module for Drupal over the Redis module is that Memcache gracefully fails over to standard Drupal caching if Memcached goes offline. On the other hand, the default configuration of the Redis integration module causes Drupal to crash if Redis Server isn’t running. Although Redis seems to be highly reliable and capable of running continuously for months on end.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s