Ejemplo n.º 1
0
 /**
  * Instantiate the Redis class.
  *
  * Instantiates the Redis class.
  *
  * @param   null $persistent_id      To create an instance that persists between requests, use persistent_id to specify a unique ID for the instance.
  */
 public function __construct()
 {
     global $blog_id, $table_prefix;
     // General Redis settings
     $redis = array('host' => '127.0.0.1', 'port' => 6379);
     if (defined('WP_REDIS_BACKEND_HOST') && WP_REDIS_BACKEND_HOST) {
         $redis['host'] = WP_REDIS_BACKEND_HOST;
     }
     if (defined('WP_REDIS_BACKEND_PORT') && WP_REDIS_BACKEND_PORT) {
         $redis['port'] = WP_REDIS_BACKEND_PORT;
     }
     if (defined('WP_REDIS_BACKEND_AUTH') && WP_REDIS_BACKEND_AUTH) {
         $redis['auth'] = WP_REDIS_BACKEND_AUTH;
     }
     if (defined('WP_REDIS_BACKEND_DB') && WP_REDIS_BACKEND_DB) {
         $redis['database'] = WP_REDIS_BACKEND_DB;
     }
     if (defined('WP_REDIS_SERIALIZER')) {
         $redis['serializer'] = WP_REDIS_SERIALIZER;
     } else {
         $redis['serializer'] = Redis::SERIALIZER_PHP;
     }
     // Use Redis PECL library.
     try {
         $this->redis = new Redis();
         $this->redis->connect($redis['host'], $redis['port']);
         $this->redis->setOption(Redis::OPT_SERIALIZER, $redis['serializer']);
         if (isset($redis['auth'])) {
             $this->redis->auth($redis['auth']);
         }
         if (isset($redis['database'])) {
             $this->redis->select($redis['database']);
         }
         $this->redis_connected = true;
     } catch (RedisException $e) {
         // When Redis is unavailable, fall back to the internal back by forcing all groups to be "no redis" groups
         $this->no_redis_groups = array_unique(array_merge($this->no_redis_groups, $this->global_groups));
         $this->redis_connected = false;
     }
     /**
      * This approach is borrowed from Sivel and Boren. Use the salt for easy cache invalidation and for
      * multi single WP installs on the same server.
      */
     if (!defined('WP_CACHE_KEY_SALT')) {
         define('WP_CACHE_KEY_SALT', '');
     }
     // Assign global and blog prefixes for use with keys
     if (function_exists('is_multisite')) {
         $this->global_prefix = is_multisite() || defined('CUSTOM_USER_TABLE') && defined('CUSTOM_USER_META_TABLE') ? '' : $table_prefix;
         $this->blog_prefix = (is_multisite() ? $blog_id : $table_prefix) . ':';
     }
 }