Example Redis with PhpRedis configuration for Drupal 7

Public

Install redis module (http://drupal.org/project/redis) and install https://github.com/nicolasff/phpredis and put these settings into settings.php file:

Get raw version
php
  1. // Checking if Redis is running, only locally.
  2. // For remote servers comment the if() statement.
  3. if (file_exists('/var/run/redis/redis-server.pid')) {
  4. $redis_up = TRUE;
  5. }
  6. if (file_exists('sites/all/modules/contrib/entitycache/entitycache.info')) {
  7. $entity_cache = TRUE;
  8. }
  9.  
  10. if (!empty($redis_up)) {
  11.  
  12. // Required configurations.
  13. $conf['lock_inc'] = 'sites/all/modules/contrib/redis/redis.lock.inc';
  14. $conf['cache_backends'][] = 'sites/all/modules/contrib/redis/redis.autoload.inc';
  15. $conf['redis_client_interface'] = 'PhpRedis';
  16. $conf['redis_client_base'] = 1;
  17. $conf['redis_client_host'] = '127.0.0.1';
  18. $conf['redis_client_port'] = '6379';
  19. // Uncomment this line if Redis is locally running via socket.
  20. // $conf['redis_cache_socket'] = '/var/run/redis/redis.sock';
  21. // $conf['cache_prefix'] = 'mysite_';
  22.  
  23. // Optional not redis specific.
  24. // $conf['cache_lifetime'] = 0;
  25. // $conf['page_cache_max_age'] = 0;
  26. // $conf['page_cache_maximum_age'] = 0;
  27. $conf['page_cache_invoke_hooks'] = TRUE;
  28. $conf['page_cache_without_database'] = FALSE;
  29. // $conf['redis_client_password'] = 'isfoobared';
  30.  
  31. // Cache bins.
  32. $conf['cache_default_class'] = 'Redis_Cache';
  33. $conf['cache_class_cache_bootstrap'] = 'Redis_Cache';
  34. $conf['cache_class_cache'] = 'Redis_Cache';
  35. $conf['cache_class_cache_menu'] = 'Redis_Cache';
  36. $conf['cache_class_cache_block'] = 'Redis_Cache';
  37. $conf['cache_class_cache_views'] = 'Redis_Cache';
  38. $conf['cache_class_cache_views_data'] = 'Redis_Cache';
  39. $conf['cache_field'] = 'Redis_Cache';
  40. $conf['cache_class_cache_field'] = 'Redis_Cache';
  41. $conf['cache_class_cache_image'] = 'Redis_Cache';
  42. $conf['cache_class_cache_libraries'] = 'Redis_Cache';
  43. $conf['cache_class_cache_metatag'] = 'Redis_Cache';
  44. $conf['cache_class_cache_search_api_solr'] = 'Redis_Cache';
  45.  
  46. // Always Database Cache.
  47. $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
  48.  
  49. // Entity Cache.
  50. if (!empty($entity_cache)) {
  51. $conf['cache_entity_node'] = 'Redis_Cache';
  52. $conf['cache_entity_fieldable_panels_pane'] = 'Redis_Cache';
  53. $conf['cache_entity_file'] = 'Redis_Cache';
  54. $conf['cache_entity_taxonomy_term'] = 'Redis_Cache';
  55. $conf['cache_entity_taxonomy_vocabulary'] = 'Redis_Cache';
  56. }
  57.  
  58. }

Comments

MXT's picture

I have a doubt: in your configuration above we can read:

$conf['cache_bootstrap'] = 'Redis_Cache';

In Redis module configuration is reported:

$conf['cache_class_cache_bootstrap'] = 'Redis_Cache';

What is the correct setting to use?

Thank you

MXT's picture

Other doubts:

1) If you use $conf['cache_default_class'] = 'Redis_Cache'; then every next conf override is absolutely useless (see poine 2 in my: https://drupal.org/node/2224385 )

2) Are you sure about:
$conf['page_cache_invoke_hooks'] = TRUE;
$conf['page_cache_without_database'] = FALSE;

Should not be instead:
$conf['page_cache_invoke_hooks'] = FALSE;
$conf['page_cache_without_database'] = TRUE;

(see: https://github.com/pantheon-systems/pantheon-settings-examples/blob/mast... )

sebas5384's picture

MXT, this is not a recommendation snippet for fasten sites, is more like a snippet for later modifications to adjust to your needs.

But hey! thanks! you are right about your points ;)