Returns a processed response to SENTINEL MASTERS or SENTINEL SLAVES.

@param array $servers List of Redis servers.

@return array
183763
protected static function processMastersOrSlaves(array $servers)
    {
        foreach ($servers as $idx => $node) {
            $processed = array();
            $count = count($node);

            for ($i = 0; $i < $count; ++$i) {
                $processed[$node[$i]] = $node[++$i];
            }

            $servers[$idx] = $processed;
        }

        return $servers;
    }
312902
public function get(array $names)
    {
        $records = $this->connection()->pipeline(function ($pipe) use ($names) {
            foreach ($names as $name) {
                $pipe->hmget('supervisor:'.$name, ['name', 'master', 'pid', 'status', 'processes', 'options']);
            }
        });

        return collect($records)->filter()->map(function ($record) {
            $record = array_values($record);

            return ! $record[0] ? null : (object) [
                'name' => $record[0],
                'master' => $record[1],
                'pid' => $record[2],
                'status' => $record[3],
                'processes' => json_decode($record[4], true),
                'options' => json_decode($record[5], true),
            ];
        })->filter()->all();
    }
268605
protected function obtainConnectedServerList(): array
    {
        $serversList = $this->getServerList();
        $servers     = [];
        
        foreach ($serversList as $serverInfos) {
            $servers[] = $serverInfos['host'].':'.$serverInfos['port'];
        }
        
        return $servers;
    }
883282
protected function getRedisHandler(array $config)
    {
        $options = array_get($config, 'redis', []);
        // In case anyone puts the servers under redis configuration - similar to how we handle cache
        $servers = array_get($options, 'servers', []);
        if (empty($servers)) {
            $servers = array_get($config, 'servers', []);
        }

        $redis = $this->getRedisInstance($servers);
        if (!empty($options['database'])) {
            $redis->select((int) $options['database']);
        }

        // In case of anyone setting prefix on the redis server directly
        // Similar to how we do it on cache
        $prefix = array_get($options, 'prefix', 'CCM_SESSION');

        // We pass the prefix to the Redis Handler when we build it
        return $this->app->make(RedisSessionHandler::class, [$redis, ['prefix' => array_get($config, 'name') ?: $prefix]]);
    }
755336
public function resolveQueues()
    {
        if (in_array('*', $this->queues)) {
            $queues = $this->redis->smembers(Queue::redisKey());
            is_array($queues) and sort($queues);
        } else {
            $queues = $this->queues;
        }

        if (!is_array($queues)) {
            $queues = array();
        }

        return $queues;
    }
1135055
def discover_slaves(self, service_name):
        ""
        for sentinel in self.sentinels:
            try:
                slaves = sentinel.sentinel_slaves(service_name)
            except (ConnectionError, ResponseError, TimeoutError):
                continue
            slaves = self.filter_slaves(slaves)
            if slaves:
                return slaves
        return []
1337987
protected function parseResponseHeadersAsArray($headers)
    {
        if (empty($headers)) return [];

        $headersArray = [];

        foreach (preg_split('#[\r\n]+#', $headers) as $headerString) {

            if ( ! preg_match('#^\s*(?<name>.*?)\s*:\s*(?<value>.*)\s*$#', $headerString, $matches)) continue;

            $headersArray[ $matches['name'] ] = $matches['value'];
        }

        return $headersArray;
    }
1163128
protected static function fetchServerHost(array $server)
    {
        if (isset($server['HTTP_HOST'])) {
            $header = $server['HTTP_HOST'];
            if (! preg_match('/(:\d+)$/', $header, $matches)) {
                return $header;
            }

            return substr($header, 0, -strlen($matches[1]));
        }

        if (isset($server['SERVER_ADDR'])) {
            return $server['SERVER_ADDR'];
        }

        throw new RuntimeException('Host could not be detected');
    }
496220
public function getAnswer(array $queries): array
    {
        $answer = [];
        foreach ($queries as $query) {
            $answer = array_merge($answer, $this->getRecordsRecursively($query));
        }

        return $answer;
    }
769827
public function getServers($type = null) {
        if ($type == Server::TYPE_MASTER)
            return $this->_masters;
        elseif ($type == Server::TYPE_SLAVE)
            return $this->_slaves;
        else
            return array_merge($this->_masters, $this->_slaves);
    }
517173
public static function normalizeServer(array $server)
    {
        // This seems to be the only way to get the Authorization header on Apache
        if (
            isset($server['HTTP_AUTHORIZATION']) ||
            !\function_exists('\apache_request_headers')
        ) {
            return $server;
        }

        $apacheRequestHeaders = \apache_request_headers();

        if (
            isset($apacheRequestHeaders[$name = 'Authorization']) ||
            isset($apacheRequestHeaders[$name = 'authorization'])
        ) {
            $server['HTTP_AUTHORIZATION'] = $apacheRequestHeaders[$name];

            return $server;
        }

        return $server;
    }
389321
protected function createSingleClients(array $servers, array $options = []) {
        $clients = array();

        foreach ($servers as $key => $server) {
        	if ($key === 'cluster') continue;

            $redis = new Redis();

            $host    = empty($server['host'])    ? '127.0.0.1' : $server['host'];
            $port    = empty($server['port'])    ? '6379'      : $server['port'];
            $timeout = empty($server['timeout']) ? 0           : $server['timeout'];

            if (isset($server['persistent']) && $server['persistent']) {
            	$redis->pconnect($host, $port, $timeout);
            } else {
            	$redis->connect($host, $port, $timeout);
            }

            if (!empty($server['prefix'])) {
            	$redis->setOption(Redis::OPT_PREFIX, $server['prefix']);
            }

            if (!empty($server['database'])) {
            	$redis->select($server['database']);
            }

            if (!empty($server['serializer'])) {
            	$serializer = Redis::SERIALIZER_NONE;
            	if ($server['serializer'] === 'php') {
            		$serializer = Redis::SERIALIZER_PHP;
            	} else if ($server['serializer'] === 'igbinary') {
            		if (defined('Redis::SERIALIZER_IGBINARY')) {
                        $serializer = Redis::SERIALIZER_IGBINARY;
                    } else {
                        $serializer = Redis::SERIALIZER_PHP;
                    }
            	}
            	$redis->setOption(Redis::OPT_SERIALIZER, $serializer);
            }

            $clients[$key] = $redis;
        }

        return $clients;
    }
1322749
protected function filterServer(array $args): array
    {
        return Collection::make($args)->filter(function ($item) {
            return !($item instanceof \Swoole\Server);
        })->toArray();
    }
1161105
public function connect(array $servers)
	{
		$memcache = $this->getEngine();

		// For each server in the array, we'll just extract the configuration and add
		// the server to the Memcached connection. Once we have added all of these
		// servers we'll verify the connection is successful and return it back.
		foreach ($servers as $server)
		{
			$memcache->addServer(
				$server['host'], $server['port'], $server['weight']
			);
		}

		if ($memcache->getVersion() === false)
		{
			throw new RuntimeException('Could not establish Memcached connection.');
		}

		// Memcahed has no list keys, we do our own accounting, initialise key index
		if ($memcache->get($this->options['hash'] . '-index') === false)
		{
			$empty = array();
			self::$_db->set($this->oprions['hash'] . '-index', $empty, $this->options['compress'], 0);
		}

		return $memcache;
	}
1320506
public function getKeys() : array
        {
	        $keys = $this->_redis->hkeys($this->_key);
	        return !empty($keys)?$keys:[];
        }
119434
private function newMemcachedServers(Memcached $memcached, array $servers)
    {
        $serverIndex = [];
        $existingServers = $memcached->getServerList();

        foreach ($existingServers as $server) {
            $serverIndex[$server['host'] . ':' . $server['port']] = true;
        }

        foreach ($servers as $configServer) {
            $server = [
                'host' => array_get($configServer, 'host', ''),
                'port' => array_get($configServer, 'port', 11211),
                'weight' => array_get($configServer, 'weight', 0),
            ];

            if (!isset($serverIndex[$server['host'] . ':' . $server['port']])) {
                yield $server;
            }
        }
    }
82233
protected function doFetch(array $ids)
    {
        if ( ! $ids) {
            return [];
        }

        return $this->redis->hmget($this->namespace, $this->keys($ids));
    }