You are here

public static function Redis_AbstractBackend::getGlobalPrefix in Redis 7.2

Get site default global prefix

Return value

string

1 call to Redis_AbstractBackend::getGlobalPrefix()
Redis_AbstractBackend::getDefaultPrefix in lib/Redis/AbstractBackend.php
Get global default prefix

File

lib/Redis/AbstractBackend.php, line 20

Class

Redis_AbstractBackend

Code

public static function getGlobalPrefix() {

  // Provide a fallback for multisite. This is on purpose not inside the
  // getPrefixForBin() function in order to decouple the unified prefix
  // variable logic and custom module related security logic, that is not
  // necessary for all backends. We can't just use HTTP_HOST, as multiple
  // hosts might be using the same database. Or, more commonly, a site
  // might not be a multisite at all, but might be using Drush leading to
  // a separate HTTP_HOST of 'default'. Likewise, we can't rely on
  // conf_path(), as settings.php might be modifying what database to
  // connect to. To mirror what core does with database caching we use
  // the DB credentials to inform our cache key.
  if (null === self::$globalPrefix) {
    if (isset($GLOBALS['db_url'])) {

      // Drupal 6 specifics when using the cache_backport module, we
      // therefore cannot use \Database class to determine database
      // settings.
      self::$globalPrefix = md5($GLOBALS['db_url']);
    }
    else {
      require_once DRUPAL_ROOT . '/includes/database/database.inc';
      $dbInfo = Database::getConnectionInfo();
      $active = $dbInfo['default'];
      self::$globalPrefix = md5($active['host'] . $active['database'] . $active['prefix']['default']);
    }
  }
  return self::$globalPrefix;
}