Use a stronger caching tool for Drupal-Redis

Source: Internet
Author: User
Tags drupal install redis
The difference between Memcache and Redis is not discussed in this article. Theoretically, if drupal's Redis module is reasonably written (without looking at the source code, let's make a rough estimate), Redis's Performance Improvement on drupal will certainly be larger than Memcache, the expansion of a single data structure saves a lot of complicated operations in Memcache, with the addition of Redi

The difference between Memcache and Redis is not discussed in this article. Theoretically, if drupal's Redis module is reasonably written (without looking at the source code, let's make a rough estimate), Redis's Performance Improvement on drupal will certainly be larger than Memcache, the expansion of a single data structure saves a lot of complicated operations in Memcache, with the addition of Redi

The difference between Memcache and Redis is not discussed in this article. Theoretically, if drupal's Redis module is reasonably written (without looking at the source code, let's make a rough estimate), Redis's Performance Improvement on drupal will certainly be larger than Memcache, the expansion of the single data structure saves a lot of complicated operations in Memcache, and Redis persistence can be used for some storage, so it can replace the functions of some databases, in addition, users who have studied the performance of Memcache will find that the bottleneck of using Memcache is not speed, but data structure processing. Therefore, we plan to use Redis for Drupal caching.

Install Redis
We use yum or apt for installation, which is relatively simple and skipped.
After the installation is complete, the redis configuration file is located at:/etc/redis. conf. You can set persistence policies and memory usage. Because redis supports VM policies, the memory bottleneck should not be a major problem. (Note the pid path, which will be used later)

Start Redis

/etc/init.d/redis-server start

After the startup is successful, you can use the redis-cli command line tool that comes with redis to enter the interactive interface. If you can enter the interface, the startup is successful.

Install PHP Extension
Redis PHP extensions include Predis and PhpRedis.
We plan to use PhpRedis because it has a PECL package, which can be directly installed and compatible with PHP5.2.
Install PECL easily.

pecl install redis

After the installation is complete, let's perform a simple PHP + Redis test.

$redis = new Redis();$redis->connect('127.0.0.1',6379);$redis->set('hello','hello world!');echo $redis->get('hello');

Output hello world! You can. You can also comment out the set statement for the second time to see if it can get the value.

Install Drupal's Redis Module
Drupal7 is used by default. Because the Redis module does not support Drupal6, you must use Cache Backport and https://drupal.org/project/cache_backportto use Redis on Drupal6. For specific operations, see the relevant documents.

drush dl redis

Note: The redis module does not need to be started. It only provides a setting interface for some third-party dependent modules, so we do not plan to start the redis module.

Redis settings of Drupal
Refer to the setting file of a person on the internet, modify it a little, and put it at the end of settings. php. The details are as follows (pay attention to modifying the redis. pid file and Path ):

if (file_exists('/var/run/redis/redis.pid')) {  $redis_up = TRUE;}if (file_exists('sites/all/modules/contrib/entitycache/entitycache.info')) {  $entity_cache = TRUE;}?if (!empty($redis_up)) {  $conf['lock_inc'] = 'sites/all/modules/contrib/redis/redis.lock.inc';  $conf['redis_cache_socket'] = '/var/run/redis/redis.sock';?  // Default behavior for all bins, prefix is 'mysite_'.  $conf['cache_prefix']['default'] = 'mysite_';? // Required configurations.  $conf['lock_inc'] = 'sites/all/modules/contrib/redis/redis.lock.inc';  $conf['cache_backends'][] = 'sites/all/modules/contrib/redis/redis.autoload.inc';  $conf['redis_client_interface'] = 'PhpRedis';  $conf['redis_client_base'] = 1;  $conf['redis_client_host'] = '127.0.0.1';  $conf['redis_client_port'] = '6379';  // $conf['cache_prefix'] = 'mysite_';?  // Optional not redis specific.  // $conf['cache_lifetime'] = 0;  // $conf['page_cache_max_age'] = 0;  // $conf['page_cache_maximum_age'] = 0;  $conf['page_cache_invoke_hooks'] = TRUE;  $conf['page_cache_without_database'] = FALSE;  // $conf['redis_client_password'] = 'isfoobared';?  // Cache bins.  $conf['cache_default_class'] = 'Redis_Cache';  $conf['cache_bootstrap'] = 'Redis_Cache';  $conf['cache_class_cache'] = 'Redis_Cache';  $conf['cache_class_cache_menu'] = 'Redis_Cache';  $conf['cache_class_cache_block'] = 'Redis_Cache';  $conf['cache_class_cache_views'] = 'Redis_Cache';  $conf['cache_class_cache_views_data'] = 'Redis_Cache';  $conf['cache_field'] = 'Redis_Cache';  $conf['cache_filter'] = 'Redis_Cache';  $conf['cache_image'] = 'Redis_Cache';  $conf['cache_libraries'] = 'Redis_Cache';  $conf['cache_metatag'] = 'Redis_Cache';  $conf['cache_search_api_solr'] = 'Redis_Cache';?  // Always Database Cache.  $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';?  // Entity Cache.  if (!empty($entity_cache)) {    $conf['cache_entity_node'] = 'Redis_Cache';    $conf['cache_entity_fieldable_panels_pane'] = 'Redis_Cache';    $conf['cache_entity_file'] = 'Redis_Cache';    $conf['cache_entity_taxonomy_term'] = 'Redis_Cache';    $conf['cache_entity_taxonomy_vocabulary'] = 'Redis_Cache';  }?}

Test
Before and after the installation, we use redis-cli to obtain data.

redis 127.0.0.1:6379:KEYS *1) "test"
redis 127.0.0.1:6379[1]:KEYS * 1) "mysite_:cache_bootstrap:hook_info" 2) "mysite_:cache:schema:runtime:1" 3) "mysite_:cache_menu:links:shortcut-set-1:tree-data:en:9bd1605e2280833450478f9083b7f8714c2fa28f1012455e2744e5af1a13eec5" 4) "mysite_:cache_menu:links:shortcut-set-1:page:node:en:1:0" 5) "mysite_:cache_bootstrap:system_list" 6) "mysite_:cache_bootstrap:module_implements"...

You can also use the INFO command to obtain

db0:keys=1,expires=0db1:keys=29,expires=29

Note: The default value is db0, And the drupal of the author is saved to db1. Therefore, you need to execute SELECT 1 to switch the current DB to db1.

If you want to test it again, you can run the TYPE command to obtain the data TYPE, such as TYPE mysite _: cache: schema: runtime: 1, and then obtain the function through the corresponding function, such as HGETALL mysite _: cache: schema: runtime: 1.

There is an article Why we recommend redis as a Drupal caching backend, which describes the advantages of using Redis. The data using newrelic is compared in this article, as shown in:

However, this is only a comparison before and after Redis, and does not use Memcache and Redis for comparison. Therefore, this performance improvement can be affirmed without argument, which is of little significance. In the future, we will compare the performance of Memcache and Redis.

Recommendation reference:

How to configure Memcache in Drupal7
Drupal custom cache shared memory

Original article address: Give Drupal a powerful cache tool-Redis. Thank you for sharing it with me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.