/**
  * 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;
     $redis = array('scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379);
     if (defined('WP_REDIS_SCHEME')) {
         $redis['scheme'] = WP_REDIS_SCHEME;
     }
     if (defined('WP_REDIS_HOST')) {
         $redis['host'] = WP_REDIS_HOST;
     }
     if (defined('WP_REDIS_PORT')) {
         $redis['port'] = WP_REDIS_PORT;
     }
     if (defined('WP_REDIS_PATH')) {
         $redis['path'] = WP_REDIS_PATH;
     }
     if (defined('WP_REDIS_PASSWORD')) {
         $redis['password'] = WP_REDIS_PASSWORD;
     }
     if (defined('WP_REDIS_DATABASE')) {
         $redis['database'] = WP_REDIS_DATABASE;
     }
     $redis_client = defined('WP_REDIS_CLIENT') ? WP_REDIS_CLIENT : null;
     if (class_exists('Redis') && strcasecmp('predis', $redis_client) !== 0) {
         $redis_client = defined('HHVM_VERSION') ? 'hhvm' : 'pecl';
     } else {
         $redis_client = 'predis';
     }
     try {
         if (strcasecmp('hhvm', $redis_client) === 0) {
             $this->redis_client = sprintf('HHVM %s Extension', HHVM_VERSION);
             $this->redis = new Redis();
             // adjust host and port, if the scheme is `unix`
             if (strcasecmp('unix', $redis['scheme']) === 0) {
                 $redis['host'] = 'unix://' . $redis['path'];
                 $redis['port'] = 0;
             }
             if (!$this->redis->connect($redis['host'], $redis['port'])) {
                 throw new Exception();
             }
             if (isset($redis['password'])) {
                 $this->redis->auth($redis['password']);
             }
             if (isset($redis['database'])) {
                 $this->redis->select($redis['database']);
             }
             $this->redis_connected = true;
         } elseif (strcasecmp('pecl', $redis_client) === 0) {
             $this->redis_client = 'PCEL Extension';
             $this->redis = new Redis();
             if (strcasecmp('unix', $redis['scheme']) === 0) {
                 $this->redis->connect($redis['path']);
             } else {
                 $this->redis->connect($redis['host'], $redis['port']);
             }
             if (isset($redis['password'])) {
                 $this->redis->auth($redis['password']);
             }
             if (isset($redis['database'])) {
                 $this->redis->select($redis['database']);
             }
             $this->redis_connected = true;
         } else {
             $this->redis_client = 'Predis';
             // require PHP 5.4 or greater
             if (version_compare(PHP_VERSION, '5.4.0', '<')) {
                 throw new Exception();
             }
             // check if bundled Predis library exists
             if (!realpath(dirname(__FILE__) . '/plugins/redis-cache/includes/predis.php')) {
                 throw new Exception();
             }
             require_once dirname(__FILE__) . '/plugins/redis-cache/includes/predis.php';
             Predis\Autoloader::register();
             $this->redis = new Predis\Client($redis);
             $this->redis->connect();
             $this->redis_connected = true;
             $this->redis_client .= ' v' . Predis\Client::VERSION;
         }
     } catch (Exception $exception) {
         // 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) . ':';
     }
 }
function redisLink() {
    global $redisHost, $redisKey;
    static $r = false;

    if ($r) return $r;
    if($redisHost && $redisKey) { // Host and Key loaded from Environment Variable
        $r = new Predis\Client($redisHost);
        $r->auth($redisKey);
    } else {
        $r = new Predis\Client();
    }
    return $r;
}
function getlink()
{
    $client = new Predis\Client(['scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379]);
    $client->auth('jakehu');
    return $client;
}
Beispiel #4
0
}
$server = $config['servers'][$i];
$server['id'] = $i;
if (isset($login, $login['servers'])) {
    if (array_search($i, $login['servers']) === false) {
        die('You are not allowed to access this database.');
    }
    foreach ($config['servers'] as $key => $ignore) {
        if (array_search($key, $login['servers']) === false) {
            unset($config['servers'][$key]);
        }
    }
}
if (!isset($server['db'])) {
    $server['db'] = 0;
}
if (!isset($server['filter'])) {
    $server['filter'] = '*';
}
// Setup a connection to Redis.
$redis = new Predis\Client('tcp://' . $server['host'] . ':' . $server['port']);
if (isset($server['auth'])) {
    if (!$redis->auth($server['auth'])) {
        die('ERROR: Authentication failed (' . $server['host'] . ':' . $server['port'] . ')');
    }
}
if ($server['db'] != 0) {
    if (!$redis->select($server['db'])) {
        die('ERROR: Selecting database failed (' . $server['host'] . ':' . $server['port'] . ',' . $server['db'] . ')');
    }
}
 /**
  * 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;
     }
     try {
         $params = ['tcp://redis-master:6379?alias=master', 'tcp://localhost:6379?alias=slave'];
         $options = ['replication' => true];
         $this->redis = new Predis\Client($params, $options);
         if (isset($redis['auth'])) {
             $this->redis->auth($redis['auth']);
         }
         if (isset($redis['database'])) {
             $this->redis->select($redis['database']);
         }
         $this->redis_connected = true;
     } catch (Predis\PredisException $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) . ':';
     }
 }
 /**
  * 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) . ':';
     }
 }