redis.module 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @file
  4. * Redis module.
  5. *
  6. * This file is a placeholder for other modules that need the Redis client for
  7. * something else than lock and cache.
  8. */
  9. // Include our own autoloader to ensure classes to be there.
  10. // We cannot rely on core in case of early bootstrap phases.
  11. require_once dirname(__FILE__) . '/redis.autoload.inc';
  12. /**
  13. * Implements hook_menu().
  14. */
  15. function redis_menu() {
  16. $items = array();
  17. $items['admin/config/development/performance/cache'] = array(
  18. 'title' => "Cache",
  19. 'type' => MENU_DEFAULT_LOCAL_TASK,
  20. );
  21. $items['admin/config/development/performance/redis'] = array(
  22. 'title' => "Redis",
  23. 'page callback' => 'drupal_get_form',
  24. 'page arguments' => array('redis_settings_form'),
  25. 'access arguments' => array('administer site configuration'),
  26. 'type' => MENU_LOCAL_TASK,
  27. 'file' => 'redis.admin.inc',
  28. );
  29. return $items;
  30. }
  31. /**
  32. * Implements hook_help().
  33. */
  34. function redis_help($path, $arg) {
  35. switch ($path) {
  36. case 'admin/config/development/performance/redis':
  37. $messages =
  38. '<p>' . t("Redis module is optional if you are using only a cache or lock backend. The full API will be automatically loaded and its configuration will live into the <em>settings.php</em> file. If you access to this screen, it's probably because another contrib module needs it as a dependency for using the Redis client. If you didn't enabled such module, you are strongly advised to disable the Redis module on the module page.") . '</p>' .
  39. '<p>' . t("While Redis client configuration can be changed through the web, if you are using a cache or lock backend they must be set in the <em>settings.php</em> file. Once this done, any modification done using this form will be ignored, and real settings in use will be get at early bootstrap phase, before the configuration system is bootstrapped.") . '</p>';
  40. if (Redis_Client::getClient()) {
  41. $messages .= '<p><strong>' . t("Current connected client uses the <em>@name</em> library.", array('@name' => Redis_Client::getClientInterfaceName())) . '</strong></p>';
  42. }
  43. return $messages;
  44. }
  45. }
  46. /**
  47. * Get Redis client for php-redis extension.
  48. *
  49. * @return \Redis
  50. */
  51. function phpredis_client_get() {
  52. if ('PhpRedis' !== variable_get('redis_client_interface')) {
  53. throw new \LogicException("Redis is not configured to use the php-redis client");
  54. }
  55. return Redis_Client::getClient();
  56. }
  57. /**
  58. * Get Redis client for Predis library.
  59. *
  60. * @return \Predis\Client
  61. */
  62. function predis_client_get() {
  63. if ('Predis' !== variable_get('redis_client_interface')) {
  64. throw new \LogicException("Redis is not configured to use the Predis client");
  65. }
  66. return Redis_Client::getClient();
  67. }