获取一个redis实例
@param string|array $server
@return Redis
420817
public static function instance($server = 'redis') {
        if(is_string($server)) {
            $server = conf($server);
            $server or $server = Config::getx('redis');
        }
        $key = $server['host'] . $server['port'].$server['db'];
        if($obj = Pool::get($key)) {
            return $obj;
        }
        $pconnect = isset($server['connect'])?$server['connect']:false;
        $obj = get_called_class()?:'nb\\utility\\Redis';
        return Pool::object($key,$obj,[
            $server['host'],$server['port'],$server['db'],$pconnect
        ]);
    }
885892
protected function createRedisStore()
    {
        $serverArray    = $this->config['servers'];
        $persistent     = boolval($this->config['persistent']);
        $prefix         = trim($this->config['prefix']);

        if ($persistent) {
            foreach ($serverArray as $k => $v) {
                $v['persistent']    = true;
                $serverArray[$k]    = $v;
            }
        }

        $redisServer    = new RedisServer($serverArray);
        return new RedisStore($redisServer, $prefix);
    }
515761
public static function createFromServer(array $server)
    {
        $scheme = self::fetchServerScheme($server);
        $host = self::fetchServerHost($server);
        $port = self::fetchServerPort($server);
        $request = self::fetchServerRequestUri($server);

        return self::createFromUrl($scheme.$host.$port.$request);
    }
1312016
public static function make(array $server = null)
    {
        if (empty($server)) {
            $server = $_SERVER;
        }

        if (isset($server['REQUEST_URI'])) {
            return parse_url($server['REQUEST_URI'], PHP_URL_PATH);
        }
    }
693924
protected function getHeadersFromServerArr(array $server) : array
    {
        $headers = [];
        $specialKeys = [
            'CONTENT_TYPE'   => 'Content-Type',
            'CONTENT_LENGTH' => 'Content-Length',
        ];
        foreach ($server as $key => $value) {
            if (substr($key, 0, 5) === 'HTTP_') {
                $header = str_replace(' ', '-',
                    ucwords(str_replace('_', ' ', strtolower(substr($key, 5))))
                );
                $headers[$header] = $value;
            } elseif (isset($specialKeys[$key])) {
                $headers[$specialKeys[$key]] = $value;
            }
        }
        
        if (!isset($headers['Authorization']) && isset($server['REDIRECT_HTTP_AUTHORIZATION'])) {
            $headers['Authorization'] = $server['REDIRECT_HTTP_AUTHORIZATION'];
        }
        
        if (isset($server['PHP_AUTH_USER'])) {
            $headers['PHP_AUTH_USER'] = $server['PHP_AUTH_USER'];
            $headers['PHP_AUTH_PW'] = $server['PHP_AUTH_PW'] ?? '';
        }
        
        return $headers;
    }
391706
private function getRedisInstance(array $servers)
    {
        if (count($servers) == 1) {
            // If we only have one server in our array then we just reconnect to it
            $server = $servers[0];
            $redis = $this->app->make(Redis::class);

            if (isset($server['socket']) && $server['socket']) {
                $redis->connect($server['socket']);
            } else {
                $host = array_get($server, 'host', '');
                $port = array_get($server, 'port', 6379);
                $ttl = array_get($server, 'ttl', 0.5);
                // Check for both server/host - fallback due to cache using server
                $host = !empty($host) ? $host : array_get($server, 'server', '127.0.0.1');

                $redis->connect($host, $port, $ttl);
            }

            // Authorisation is handled by just a password
            if (isset($server['password'])) {
                $redis->auth($server['password']);
            }
        } else {
            $serverArray = [];
            $ttl = 0.5;
            foreach ($this->getRedisServers($servers) as $server) {
                $serverString = $server['server'];
                if (isset($server['port'])) {
                    $serverString .= ':' . $server['port'];
                }
                // We can only use one ttl for connection timeout so use the last set ttl
                // isset allows for 0 - unlimited
                if (!isset($server['ttl'])) {
                    $ttl = $server['ttl'];
                }

                $serverArray[] = $serverString;
            }
            $redis = $this->app->make(RedisArray::class, [$serverArray, ['connect_timeout' => $ttl]]);
        }

        return $redis;
    }
522511
private function createUriFromArray(array $server): UriInterface
    {
        $uri = $this->uriFactory->createUri('');

        if (isset($server['REQUEST_SCHEME'])) {
            $uri = $uri->withScheme($server['REQUEST_SCHEME']);
        } elseif (isset($server['HTTPS'])) {
            $uri = $uri->withScheme('on' === $server['HTTPS'] ? 'https' : 'http');
        }

        if (isset($server['SERVER_PORT'])) {
            $uri = $uri->withPort($server['SERVER_PORT']);
        }

        if (isset($server['HTTP_HOST'])) {
            if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) {
                $uri = $uri->withHost($matches[1])->withPort($matches[2]);
            } else {
                $uri = $uri->withHost($server['HTTP_HOST']);
            }
        } elseif (isset($server['SERVER_NAME'])) {
            $uri = $uri->withHost($server['SERVER_NAME']);
        }

        if (isset($server['REQUEST_URI'])) {
            $uri = $uri->withPath(\current(\explode('?', $server['REQUEST_URI'])));
        }

        if (isset($server['QUERY_STRING'])) {
            $uri = $uri->withQuery($server['QUERY_STRING']);
        }

        return $uri;
    }
1373282
public static function make(array $server = null)
    {
        $scheme = UriSchemeFactory::make($server);
        $host   = UriHostFactory::make($server);
        $port   = UriPortFactory::make($server);
        $path   = UriPathFactory::make($server);
        $query  = UriQueryFactory::make($server);

        $url = '';
        if ($host) {
            $url .= $scheme . '://' . $host . ':' . $port;
            $path = '/' . ltrim($path, '/');
        }
        $url .= $path;

        if ($query) {
            $url .= '?' . $query;
        }

        $uri = new Uri($url);

        if ($host) {
            return $uri;
        }

        return $uri->withScheme($scheme)->withPort($port);
    }
511496
public function connect(array $config)
    {
        return new RedisQueue(
            $this->redis, $config['queue'],
            Arr::get($config, 'connection', $this->connection),
            Arr::get($config, 'retry_after', 60),
            Arr::get($config, 'block_for', null)
        );
    }
1217634
public static function createUri(array $server = [])
    {
        $server += $_SERVER;
        $server = static::normalizeServer($server);
        $headers = static::marshalHeaders($server);

        return static::marshalUriFromServer($server, $headers);
    }
177423
public static function fromArray(array $server)
    {
        $uri = new self('');

        if (isset($server['HTTPS'])) {
            $uri->scheme = $server['HTTPS'] === 'on' ? 'https' : 'http';
        }

        [$host, $port] = Helpers::getHostAndPortFromArray($server);

        $uri->host = \strtolower($host);
        $uri->port = $uri->filterPort($port);

        $path = Helpers::getRequestUri($server);

        $fragment = '';
        if (\strpos($path, '#') !== false) {
            [$path, $fragment] = \explode('#', $path, 2);
        }

        $uri->path = $uri->filterPath(\explode('?', $path, 2)[0]);
        $uri->fragment = $uri->filterFragment($fragment);

        if (isset($server['QUERY_STRING'])) {
            $uri->query = $uri->filterQuery($server['QUERY_STRING']);
        }

        return $uri;
    }
673334
protected function findAuthHeader(array $server) {
        if (array_has($server, 'HTTP_AUTHORIZATION')) {
            return array_get($server, 'HTTP_AUTHORIZATION');
        } else if (array_has($server, 'REDIRECT_HTTP_AUTHORIZATION')) {
            return array_get($server, 'REDIRECT_HTTP_AUTHORIZATION');
        }

        return null;
    }
368589
protected function getHotReloadProcess($server)
    {
        $recursively = Arr::get($this->config, 'hot_reload.recursively');
        $directory = Arr::get($this->config, 'hot_reload.directory');
        $filter = Arr::get($this->config, 'hot_reload.filter');
        $log = Arr::get($this->config, 'hot_reload.log');

        $cb = function (FSEvent $event) use ($server, $log) {
            $log ? $this->info(FSOutput::format($event)) : null;
            $server->reload();
        };

        return (new FSProcess($filter, $recursively, $directory))->make($cb);
    }
796621
protected static function fetchServerScheme(array $server)
    {
        $scheme = '';
        if (isset($server['SERVER_PROTOCOL'])) {
            $scheme = explode('/', $server['SERVER_PROTOCOL']);
            $scheme = strtolower($scheme[0]);
            if (isset($server['HTTPS']) && 'off' != $server['HTTPS']) {
                $scheme .= 's';
            }
            $scheme .= ':';
        }

        return $scheme.'//';
    }
203301
protected function createAggregateClient(array $servers, array $options = [])
    {
        $servers = array_map([$this, 'buildClusterSeed'], $servers);

        $timeout = empty($options['timeout']) ? 0 : $options['timeout'];
        $persistent = isset($options['persistent']) && $options['persistent'];

        return ['default' => new RedisCluster(
            null, array_values($servers), $timeout, null, $persistent
        )];
    }
195357
def _get_redis_server(opts=None):
    '''
    
    '''
    global REDIS_SERVER
    if REDIS_SERVER:
        return REDIS_SERVER
    if not opts:
        opts = _get_redis_cache_opts()

    if opts['cluster_mode']:
        REDIS_SERVER = StrictRedisCluster(startup_nodes=opts['startup_nodes'],
                                          skip_full_coverage_check=opts['skip_full_coverage_check'])
    else:
        REDIS_SERVER = redis.StrictRedis(opts['host'],
                                   opts['port'],
                                   unix_socket_path=opts['unix_socket_path'],
                                   db=opts['db'],
                                   password=opts['password'])
    return REDIS_SERVER
686059
function getServer($servers)
    {
        if (empty($servers))
        {
            throw new \Exception("servers config empty.");
        }

        if ($this->keepSocket)
        {
            if (is_array($this->keepSocketServer) && count($this->keepSocketServer))
            {
                return $this->keepSocketServer;
            }
            else
            {
                $this->keepSocketServer = Tool::getServer($servers);

                return $this->keepSocketServer;
            }
        }

        //保留老的server获取方式
        return Tool::getServer($servers);
    }