Parse Redis Sentinel connection host definitions to create single host
entries for host definitions that specify multiple hosts.

@return void
551811
protected function normalizeHosts()
    {
        $connections = $this->config->get('database.redis-sentinel');

        if (! is_array($connections)) {
            return;
        }

        $this->config->set(
            'database.redis-sentinel',
            HostNormalizer::normalizeConnections($connections)
        );
    }
1368829
def _sconnect(host=None, port=None, password=None):
    '''
    
    '''
    if host is None:
        host = __salt__['config.option']('redis_sentinel.host', 'localhost')
    if port is None:
        port = __salt__['config.option']('redis_sentinel.port', 26379)
    if password is None:
        password = __salt__['config.option']('redis_sentinel.password')

    return redis.StrictRedis(host, port, password=password, decode_responses=True)
1017202
public void initWithHosts(Map<Host, HostConnectionPool<CL>> hPools) {

		// Get the list of tokens for these hosts
		//tokenSupplier.initWithHosts(hPools.keySet());
		List<HostToken> allHostTokens = tokenSupplier.getTokens(hPools.keySet());
		Map<HostToken, HostConnectionPool<CL>> tokenPoolMap = new HashMap<HostToken, HostConnectionPool<CL>>();
	        
		// Update inner state with the host tokens.
		for (HostToken hToken : allHostTokens) {
			hostTokens.put(hToken.getHost(), hToken);
			tokenPoolMap.put(hToken, hPools.get(hToken.getHost()));
		}

		// Initialize Local selector
		Map<HostToken, HostConnectionPool<CL>> localPools = getHostPoolsForRack(tokenPoolMap, localRack);
		localSelector.initWithHosts(localPools);
		if (localSelector.isTokenAware() && localRack != null) {
		   replicationFactor.set(calculateReplicationFactor(allHostTokens));
		}

		// Initialize Remote selectors
		Set<String> remoteRacks = new HashSet<String>();
		for (Host host : hPools.keySet()) {
			String rack = host.getRack();
			if (localRack != null && !localRack.isEmpty() && rack != null && !rack.isEmpty() && !localRack.equals(rack)) {
				remoteRacks.add(rack);
			}
		}

		for (String rack : remoteRacks) {
			Map<HostToken, HostConnectionPool<CL>> dcPools = getHostPoolsForRack(tokenPoolMap, rack);
			HostSelectionStrategy<CL> remoteSelector = selectorFactory.vendPoolSelectionStrategy();
			remoteSelector.initWithHosts(dcPools);
			remoteRackSelectors.put(rack, remoteSelector);
		}

		remoteDCNames.swapWithList(remoteRackSelectors.keySet());

        topology.set(createTokenPoolTopology(allHostTokens));
	}
712881
public static function parse_socket_options(&$options, $host = null)
    {
        if (empty($host) || empty($options)) {
            return $options;
        }

        // get rid of schema and port from the hostname
        $host_url = parse_url($host);
        if (isset($host_url['host'])) {
            $host = $host_url['host'];
        }

        // find per-host options
        if (array_key_exists($host, $options)) {
            $options = $options[$host];
        }
    }
600981
def parse_host(parser, event, node):
    
    #pylint: disable=unused-argument

    host = ''

    (next_event, next_node) = six.next(parser)

    if next_event == pulldom.CHARACTERS:

        host = next_node.nodeValue

        (next_event, next_node) = six.next(parser)

    if not _is_end(next_event, next_node, 'HOST'):
        raise ParseError('Expecting end HOST')

    return host
97902
public function get_hostlist()
    {
        $default_hosts = (array) $this->getprop('default_host');
        $out           = array();

        foreach ($default_hosts as $key => $name) {
            if (!empty($name)) {
                $out[] = rcube_utils::parse_host(is_numeric($key) ? $name : $key);
            }
        }

        return $out;
    }
1220230
protected function addRedisSentinelBroadcaster()
    {
        $this->app->make(BroadcastFactory::class)
            ->extend('redis-sentinel', function ($app, $conf) {
                $redis = $app->make('redis-sentinel.manager');
                $connection = Arr::get($conf, 'connection', 'default');

                return new RedisBroadcaster($redis, $connection);
            });
    }
63101
public function connect()
    {
        $connection = $this->config->get('redis_connection');
        $params = array('prefix' => $this->config->get('redis_prefix').':');

        // connect to redis using the connection details in the config file
        $this->redis = new \Predis\Client(
            $connection,
            $params
            );
    }
534053
public function setHost($host = null)
    {
        if ($host === null) {
            $host = '127.0.0.1';
        }

        if (substr($host, 0, 6) == 'ssl://') {
            $this->_protocol = 'ssl';
            $this->_secure = 'ssl';
            $host = substr($host, 6);
        }
        $this->_host = $host;
    }
402732
protected function initInstances()
    {
        if (empty($this->instances)) {
            foreach ($this->servers as $server) {
                if ($server instanceof \Redis) {
                    if ($server->isConnected()) {
                        $redis = $server;
                    } else {
                        throw new \InvalidArgumentException("If you use \\Redis objects as argument, the object must be connected.");
                    }
                } else {
                    if (empty($server[0])) {
                        throw new \InvalidArgumentException("A server hostname or IP is required");
                    }

                    if (empty($server[1])) {
                        $server[1] = 6379;
                    }
                    if (empty($server[2])) {
                        $server[2] = 0;
                    }
                    list($host, $port, $timeout) = $server;
                    $redis = new \Redis();
                    $redis->connect($host, $port, $timeout);
                }
                $this->instances[] = $redis;
            }
        }
    }
1213919
private function connection__redis() {
		$this->connection = new \Redis();
		# @note: This emits warning on failure instead of throwing
		# exception, hence the @ sign.
		if (!@$this->connection->connect(
			$this->redishost, $this->redisport,
			$this->redistimeout
		))
			// @codeCoverageIgnoreStart
			return $this->connection_open_fail();
			// @codeCoverageIgnoreEnd
		if ($this->redispassword || $this->redisdatabase) {
			try {
				if ($this->redispassword)
					$this->connection->auth($this->redispassword);
				if ($this->redisdatabase)
					$this->connection->select($this->redisdatabase);
			} catch(\RedisException $e) {
				return $this->connection_open_fail($e->getMessage());
			}
		}
		try {
			$this->connection->ping();
		} catch(\RedisException $e) {
			return $this->connection_open_fail($e->getMessage());
		}
		return $this->connection_open_ok();
	}
897175
public function connect()
    {
        if (null !== $this->redis) {
            return;
        }

        $this->redis = new \Redis();
        $this->redis->connect($this->host, $this->port);
        if (null !== $this->base) {
            try {
                $this->redis->select($this->base);
            } catch (\RedisException $e) {
                throw new \RedisException(sprintf('%s (%s:%d)', $e->getMessage(), $this->host, $this->port), $e->getCode(), $e);
            }
        }
    }
596004
public function parse()
    {

        // load the deployment descriptors that has to be parsed
        $deploymentDescriptors = $this->loadDeploymentDescriptors();

        // parse the deployment descriptors from the conf.d and the application's META-INF directory
        foreach ($deploymentDescriptors as $deploymentDescriptor) {
            // query whether we found epb.xml deployment descriptor file
            if (file_exists($deploymentDescriptor) === false) {
                continue;
            }

            // validate the passed configuration file
            /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */
            $configurationService = $this->getApplication()->newService('AppserverIo\Appserver\Core\Api\ConfigurationService');
            $configurationService->validateFile($deploymentDescriptor, null, true);

            // load the object manager instance
            /** @var \AppserverIo\Psr\Di\ObjectManagerInterface $objectManager */
            $objectManager = $this->getApplication()->search(ObjectManagerInterface::IDENTIFIER);

            // prepare and initialize the configuration node
            $webAppNode = new WebAppNode();
            $webAppNode->initFromFile($deploymentDescriptor);

            /** @var \AppserverIo\Appserver\Core\Api\Node\ServletNode $servletNode */
            foreach ($webAppNode->getServlets() as $servletNode) {
                // iterate over all configured descriptors and try to load object description
                /** \AppserverIo\Appserver\Core\Api\Node\DescriptorNode $descriptor */
                foreach ($this->getDescriptors() as $descriptor) {
                    try {
                        // load the descriptor class
                        $descriptorClass = $descriptor->getNodeValue()->getValue();

                        // load the object descriptor, initialize the servlet mappings and add it to the object manager
                        /** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */
                        if ($objectDescriptor = $descriptorClass::newDescriptorInstance()->fromConfiguration($servletNode)) {
                            /** @var \AppserverIo\Appserver\Core\Api\Node\ServletMappingNode $servletMappingNode */
                            foreach ($webAppNode->getServletMappings() as $servletMappingNode) {
                                // query whether or not we've to add the URL pattern for the servlet
                                if ((string) $servletNode->getServletName() === (string) $servletMappingNode->getServletName()) {
                                    $objectDescriptor->addUrlPattern((string) $servletMappingNode->getUrlPattern());
                                }
                            }

                            // add the object descriptor for the servlet
                            $objectManager->addObjectDescriptor($objectDescriptor, true);
                        }

                        // proceed with the next descriptor
                        continue;

                    // if class can not be reflected continue with next class
                    } catch (\Exception $e) {
                        // log an error message
                        $this->getApplication()->getInitialContext()->getSystemLogger()->error($e->__toString());

                        // proceed with the next descriptor
                        continue;
                    }
                }
            }

            // initialize the session configuration if available
            /** @var \AppserverIo\Appserver\Core\Api\Node\SessionConfigNode $sessionConfig */
            if ($sessionConfig = $webAppNode->getSessionConfig()) {
                foreach ($sessionConfig->toArray() as $key => $value) {
                    $this->getManager()->addSessionParameter($key, $value);
                }
            }

            // initialize the error page configuration if available
            /** @var \AppserverIo\Appserver\Core\Api\Node\ErrorPageNode $errorPageNode */
            foreach ($webAppNode->getErrorPages() as $errorPageNode) {
                $this->getManager()->addErrorPage((string) $errorPageNode->getErrorCodePattern(), (string) $errorPageNode->getErrorLocation());
            }

            // initialize the context with the context parameters
            /** @var \AppserverIo\Appserver\Core\Api\Node\ContextParamNode $contextParamNode */
            foreach ($webAppNode->getContextParams() as $contextParamNode) {
                $this->getManager()->addInitParameter((string) $contextParamNode->getParamName(), (string) $contextParamNode->getParamValue());
            }
        }
    }
513583
public static Hosts parse(String hostString, Integer explicitGlobalPort, Integer defaultPort) {
		List<String> hosts = new ArrayList<>();
		List<Integer> ports = new ArrayList<>();
		if ( hostString == null || hostString.trim().isEmpty() ) {
			return Hosts.NO_HOST;
		}
		// for each element between commas
		String[] splits = hostString.split( "," );
		for ( String rawSplit : splits ) {
			// remove whitespaces
			String split = rawSplit.trim();
			//
			Matcher matcher = HOST_AND_PORT_PATTERN.matcher( split );
			if ( matcher.matches() ) {
				setCleanHost( matcher, hosts );
				setPort( ports, matcher, explicitGlobalPort, splits, defaultPort );
			}
			else {
				throw LOG.unableToParseHost( hostString );
			}
		}
		return new Hosts( hosts, ports );
	}
1210538
private function connect()
	{
		// We want to only create the driver once.
		if (isset($this->driver))
		{
			return;
		}

		$host = isset($this->options['redis.host'])? $this->options['redis.host'] : self::REDIS_HOST;
		$port = isset($this->options['redis.port'])? $this->options['redis.port'] : self::REDIS_PORT;

		$this->driver = new RedisDriver;

		if (($host == 'localhost' || filter_var($host, FILTER_VALIDATE_IP)))
		{
			$this->driver->connect('tcp://' . $host . ':' . $port, $port);
		}
		else
		{
			$this->driver->connect($host, null);
		}
	}
602050
protected function _hostname() {
        $components = parse_url(Router::url('/', true));
        if (isset($components['host'])) {
            return $components['host'];
        }
        return null;
    }
193227
private function resolveDefaultHostName()
    {
        $request = $this->di->get('request');
        $config = $this->di->get('config');
        if (isset($config->application->hostname)) {
            $hostName = $config->application->hostname;
        } else if ($request->getServer('HTTP_HOST')) {
            $hostName = $request->getServer('HTTP_HOST');
        } else {
            $hostName = null;
        }
        if (null !== $hostName) {
            $hostName = '(www\.)?' . $hostName;
        }

        return $hostName;
    }