/**
  * @see RCFeedEngine::send
  */
 public function send(array $feed, $line)
 {
     $parsed = wfParseUrl($feed['uri']);
     $server = $parsed['host'];
     $options = ['serializer' => 'none'];
     $channel = 'rc';
     if (isset($parsed['port'])) {
         $server .= ":{$parsed['port']}";
     }
     if (isset($parsed['query'])) {
         parse_str($parsed['query'], $options);
     }
     if (isset($parsed['pass'])) {
         $options['password'] = $parsed['pass'];
     }
     if (isset($parsed['path'])) {
         $channel = str_replace('/', '.', ltrim($parsed['path'], '/'));
     }
     $pool = RedisConnectionPool::singleton($options);
     $conn = $pool->getConnection($server);
     if ($conn !== false) {
         $conn->publish($channel, $line);
         return true;
     } else {
         return false;
     }
 }
 /**
  * @params include:
  *   - redisConfig  : An array of parameters to RedisConnectionPool::__construct().
  *   - redisServers : Array of server entries, the first being the primary and the
  *                    others being fallback servers. Each entry is either a hostname/port
  *                    combination or the absolute path of a UNIX socket.
  *                    If a hostname is specified but no port, the standard port number
  *                    6379 will be used. Required.
  * @param array $params
  */
 protected function __construct(array $params)
 {
     parent::__construct($params);
     $this->servers = isset($params['redisServers']) ? $params['redisServers'] : array($params['redisServer']);
     // b/c
     $this->redisPool = RedisConnectionPool::singleton($params['redisConfig']);
 }
Пример #3
0
	/**
	 * @params include:
	 *   - redisConfig : An array of parameters to RedisConnectionPool::__construct().
	 *                   Note that the serializer option is ignored "none" is always used.
	 *   - redisServer : A hostname/port combination or the absolute path of a UNIX socket.
	 *                   If a hostname is specified but no port, the standard port number
	 *                   6379 will be used. Required.
	 *   - compression : The type of compression to use; one of (none,gzip).
	 * @param array $params
	 */
	public function __construct( array $params ) {
		parent::__construct( $params );
		$params['redisConfig']['serializer'] = 'none'; // make it easy to use Lua
		$this->server = $params['redisServer'];
		$this->compression = isset( $params['compression'] ) ? $params['compression'] : 'none';
		$this->redisPool = RedisConnectionPool::singleton( $params['redisConfig'] );
	}
 /**
  * @param array $params Possible keys:
  *   - redisConfig  : An array of parameters to RedisConnectionPool::__construct().
  *   - redisServers : Array of server entries, the first being the primary and the
  *                    others being fallback servers. Each entry is either a hostname/port
  *                    combination or the absolute path of a UNIX socket.
  *                    If a hostname is specified but no port, the standard port number
  *                    6379 will be used. Required.
  */
 public function __construct(array $params)
 {
     parent::__construct($params);
     $this->servers = isset($params['redisServers']) ? $params['redisServers'] : array($params['redisServer']);
     // b/c
     $params['redisConfig']['serializer'] = 'none';
     $this->redisPool = RedisConnectionPool::singleton($params['redisConfig']);
 }
Пример #5
0
 /**
  * @param array $params Possible keys:
  *   - redisConfig  : An array of parameters to RedisConnectionPool::__construct().
  *   - redisServers : Array of server entries, the first being the primary and the
  *                    others being fallback servers. Each entry is either a hostname/port
  *                    combination or the absolute path of a UNIX socket.
  *                    If a hostname is specified but no port, the standard port number
  *                    6379 will be used. Required.
  */
 public function __construct(array $params)
 {
     parent::__construct($params);
     $this->servers = isset($params['redisServers']) ? $params['redisServers'] : [$params['redisServer']];
     // b/c
     $params['redisConfig']['serializer'] = 'none';
     $this->redisPool = RedisConnectionPool::singleton($params['redisConfig']);
     $this->logger = \MediaWiki\Logger\LoggerFactory::getInstance('redis');
 }
 /**
  * @params include:
  *   - redisServers : list of servers (address:<port>) (the first is the master)
  *   - redisConf    : additional redis configuration
  *
  * @param array $config
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $redisConf = $config['redisConfig'];
     $redisConf['serializer'] = 'none';
     // manage that in this class
     $this->redisPool = RedisConnectionPool::singleton($redisConf);
     $this->servers = $config['redisServers'];
     $this->lockMgr = new RedisLockManager(array('lockServers' => array('srv1' => $this->servers[0]), 'srvsByBucket' => array(0 => array('srv1')), 'redisConfig' => $config['redisConfig']));
 }
Пример #7
0
 /**
  * Construct a new instance from configuration.
  *
  * @param array $config Parameters include:
  *   - lockServers  : Associative array of server names to "<IP>:<port>" strings.
  *   - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
  *                    each having an odd-numbered list of server names (peers) as values.
  *   - redisConfig  : Configuration for RedisConnectionPool::__construct().
  * @throws Exception
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $this->lockServers = $config['lockServers'];
     // Sanitize srvsByBucket config to prevent PHP errors
     $this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
     $this->srvsByBucket = array_values($this->srvsByBucket);
     // consecutive
     $config['redisConfig']['serializer'] = 'none';
     $this->redisPool = RedisConnectionPool::singleton($config['redisConfig']);
 }
Пример #8
0
	/**
	 * Construct a RedisBagOStuff object. Parameters are:
	 *
	 *   - servers: An array of server names. A server name may be a hostname,
	 *     a hostname/port combination or the absolute path of a UNIX socket.
	 *     If a hostname is specified but no port, the standard port number
	 *     6379 will be used. Required.
	 *
	 *   - connectTimeout: The timeout for new connections, in seconds. Optional,
	 *     default is 1 second.
	 *
	 *   - persistent: Set this to true to allow connections to persist across
	 *     multiple web requests. False by default.
	 *
	 *   - password: The authentication password, will be sent to Redis in
	 *     clear text. Optional, if it is unspecified, no AUTH command will be
	 *     sent.
	 *
	 *   - automaticFailover: If this is false, then each key will be mapped to
	 *     a single server, and if that server is down, any requests for that key
	 *     will fail. If this is true, a connection failure will cause the client
	 *     to immediately try the next server in the list (as determined by a
	 *     consistent hashing algorithm). True by default. This has the
	 *     potential to create consistency issues if a server is slow enough to
	 *     flap, for example if it is in swap death.
	 */
	function __construct( $params ) {
		$redisConf = array( 'serializer' => 'php' );
		foreach ( array( 'connectTimeout', 'persistent', 'password' ) as $opt ) {
			if ( isset( $params[$opt] ) ) {
				$redisConf[$opt] = $params[$opt];
			}
		}
		$this->redisPool = RedisConnectionPool::singleton( $redisConf );

		$this->servers = $params['servers'];
		if ( isset( $params['automaticFailover'] ) ) {
			$this->automaticFailover = $params['automaticFailover'];
		} else {
			$this->automaticFailover = true;
		}
	}
Пример #9
0
 /**
  * Acquire a Redis connection.
  *
  * @access	protected
  * @param	string	[Optiona] Server group key. 
  * 					Example: 'cache' would look up $wgRedisServers['cached']
  *					Default: Uses the first index of $wgRedisServers.
  * @param	array	[Optional] Additional options, will merge and overwrite default options.
  *					- connectTimeout : The timeout for new connections, in seconds.
  *                      Optional, default is 1 second.
  *					- persistent     : Set this to true to allow connections to persist across
  *                      multiple web requests. False by default.
  *					- password       : The authentication password, will be sent to Redis in clear text.
  *                      Optional, if it is unspecified, no AUTH command will be sent.
  *					- serializer     : Set to "php", "igbinary", or "none". Default is "php".
  * @param	boolean	[Optional] Force a new connection, useful when forking processes.
  * @return	mixed	Object RedisConnRef or false on failure.
  */
 public static function getClient($group = null, $options = [], $newConnection = false)
 {
     global $wgRedisServers;
     if (!extension_loaded('redis')) {
         throw new MWException(__METHOD__ . " - The PHP Redis extension is not available.  Please enable it on the server to use RedisCache.");
     }
     if (empty($wgRedisServers) || !is_array($wgRedisServers)) {
         MWDebug::log(__METHOD__ . " - \$wgRedisServers must be configured for RedisCache to function.");
         return false;
     }
     if (empty($group)) {
         $group = 0;
         $server = current($wgRedisServers);
     } else {
         $server = $wgRedisServers[$group];
     }
     if ($newConnection === false && array_key_exists($group, self::$servers)) {
         return self::$servers[$group];
     }
     if (empty($server) || !is_array($server)) {
         throw new MWException(__METHOD__ . " - An invalid server group key was passed.");
     }
     $pool = \RedisConnectionPool::singleton(array_merge($server['options'], $options));
     $redis = $pool->getConnection($server['host'] . ":" . $server['port']);
     //Concatenate these together for MediaWiki weirdness so it can split them later.
     if ($redis instanceof RedisConnRef) {
         //Set up any extra options.  RedisConnectionPool does not handle the prefix automatically.
         if (!empty($server['options']['prefix'])) {
             $redis->setOption(Redis::OPT_PREFIX, $server['options']['prefix']);
         }
         try {
             $pong = $redis->ping();
             if ($pong === '+PONG') {
                 self::$servers[$group] = $redis;
             } else {
                 $redis = false;
             }
         } catch (RedisException $e) {
             //People using HAProxy will find it will lie about a Redis cluster being healthy when the master is down, but the slaves are up.  Doing a PING will cause an immediate disconnect.
             self::$lastError = $e->getMessage();
             $redis = false;
         }
     }
     return $redis;
 }
Пример #10
0
 /**
  * Construct a RedisBagOStuff object. Parameters are:
  *
  *   - servers: An array of server names. A server name may be a hostname,
  *     a hostname/port combination or the absolute path of a UNIX socket.
  *     If a hostname is specified but no port, the standard port number
  *     6379 will be used. Arrays keys can be used to specify the tag to
  *     hash on in place of the host/port. Required.
  *
  *   - connectTimeout: The timeout for new connections, in seconds. Optional,
  *     default is 1 second.
  *
  *   - persistent: Set this to true to allow connections to persist across
  *     multiple web requests. False by default.
  *
  *   - password: The authentication password, will be sent to Redis in
  *     clear text. Optional, if it is unspecified, no AUTH command will be
  *     sent.
  *
  *   - automaticFailover: If this is false, then each key will be mapped to
  *     a single server, and if that server is down, any requests for that key
  *     will fail. If this is true, a connection failure will cause the client
  *     to immediately try the next server in the list (as determined by a
  *     consistent hashing algorithm). True by default. This has the
  *     potential to create consistency issues if a server is slow enough to
  *     flap, for example if it is in swap death.
  * @param array $params
  */
 function __construct($params)
 {
     parent::__construct($params);
     $redisConf = array('serializer' => 'none');
     // manage that in this class
     foreach (array('connectTimeout', 'persistent', 'password') as $opt) {
         if (isset($params[$opt])) {
             $redisConf[$opt] = $params[$opt];
         }
     }
     $this->redisPool = RedisConnectionPool::singleton($redisConf);
     $this->servers = $params['servers'];
     foreach ($this->servers as $key => $server) {
         $this->serverTagMap[is_int($key) ? $server : $key] = $server;
     }
     if (isset($params['automaticFailover'])) {
         $this->automaticFailover = $params['automaticFailover'];
     } else {
         $this->automaticFailover = true;
     }
 }
Пример #11
0
 function __construct($conf, $type, $key)
 {
     parent::__construct($conf, $type, $key);
     $this->serversByLabel = $conf['servers'];
     $this->ring = new HashRing(array_fill_keys(array_keys($conf['servers']), 100));
     $conf['redisConfig']['serializer'] = 'none';
     // for use with Lua
     $this->pool = RedisConnectionPool::singleton($conf['redisConfig']);
     $this->logger = \MediaWiki\Logger\LoggerFactory::getInstance('redis');
     $this->keySha1 = sha1($this->key);
     $met = ini_get('max_execution_time');
     // usually 0 in CLI mode
     $this->lockTTL = $met ? 2 * $met : 3600;
     if (self::$active === null) {
         self::$active = [];
         register_shutdown_function([__CLASS__, 'releaseAll']);
     }
 }
Пример #12
0
 /**
  * @param array $params Possible keys:
  *   - redisConfig : An array of parameters to RedisConnectionPool::__construct().
  *                   Note that the serializer option is ignored as "none" is always used.
  *   - redisServer : A hostname/port combination or the absolute path of a UNIX socket.
  *                   If a hostname is specified but no port, the standard port number
  *                   6379 will be used. Required.
  *   - compression : The type of compression to use; one of (none,gzip).
  *   - daemonized  : Set to true if the redisJobRunnerService runs in the background.
  *                   This will disable job recycling/undelaying from the MediaWiki side
  *                   to avoid redundance and out-of-sync configuration.
  * @throws InvalidArgumentException
  */
 public function __construct(array $params)
 {
     parent::__construct($params);
     $params['redisConfig']['serializer'] = 'none';
     // make it easy to use Lua
     $this->server = $params['redisServer'];
     $this->compression = isset($params['compression']) ? $params['compression'] : 'none';
     $this->redisPool = RedisConnectionPool::singleton($params['redisConfig']);
     if (empty($params['daemonized'])) {
         throw new InvalidArgumentException("Non-daemonized mode is no longer supported. Please install the " . "mediawiki/services/jobrunner service and update \$wgJobTypeConf as needed.");
     }
 }
 /**
  * @params include:
  *   - redisConfig : An array of parameters to RedisConnectionPool::__construct().
  *   - redisServer : A hostname/port combination or the absolute path of a UNIX socket.
  *                   If a hostname is specified but no port, the standard port number
  *                   6379 will be used. Required.
  * @param array $params
  */
 protected function __construct(array $params)
 {
     parent::__construct($params);
     $this->server = $params['redisServer'];
     $this->redisPool = RedisConnectionPool::singleton($params['redisConfig']);
 }