Get a Redis database connection instance.

The given name should correspond to a Redis database in the configuration file.

@param string $name

@return Redis
@throws \RuntimeException
974459
public static function database($name = 'default')
    {
        if (!isset(static::$databases[$name])) {

            $cache = Config::get('cache');

            if (!isset($cache['storage']) || $cache['storage'] != 'redis') {
                throw new \RuntimeException("Redis database [$name] is not defined.");
            }

            static::$databases[$name] = new static(
                new Adapter\Socket($cache['server']['host'], $cache['server']['port']),
                $cache['server']['database']
            );
        }

        return static::$databases[$name];
    }
170600
public function create($name)
    {
        $config = $this->getConfiguration($name);

        if(null === $config) {
            throw new \RuntimeException(
                "Connection with name: $name not found."
            );
        }

        return new Client($config);
    }
1304718
public static function get($name, $key = 'main')
    {
        if (in_array($name, ['sql', 'redis', 'elastic'])) {
            $resource = cradle('global')->service($name . '-' . $key);

            if ($resource) {
                if ($name === 'sql') {
                    return new SqlService($resource);
                }

                if ($name === 'redis') {
                    return new RedisService($resource);
                }

                if ($name === 'elastic') {
                    return new ElasticService($resource);
                }
            }
        }

        return new NoopService();
    }
122104
protected function getConnectionByName($name)
    {
        if (array_key_exists($name, $this->connectionByName)) {
            return $this->connectionByName[$name];
        }

        $event = clone $this->getManagerRegistryResourceEventPrototype();
        $event->setName(ManagerRegistryResourceEvent::RESOLVE_CONNECTION_EVENT);
        $event->setResourceName($name);
        $event->setTarget($this);


        $resultsEvent = $this->getEventManager()->trigger($event, function ($connection) {
            return is_object($connection);
        });

        $connection = $resultsEvent->last();

        if (!is_object($connection)) {
            $errMsg = sprintf('Connection %s not found', $name);
            throw new Exception\ConnectionNotFoundException($errMsg);
        }

        $this->connectionByName[$name] = $connection;

        return $this->connectionByName[$name];
    }
443726
public static function connection($name = 'default')
    {
        $databaseConfig = self::getConnectionConfiguration($name);

        /** @var Driver $driver */
        $driver = self::driver($name);

        $username = isset($databaseConfig['username']) ? $databaseConfig['username'] : null;
        $password = isset($databaseConfig['password']) ? $databaseConfig['password'] : null;
        $options = isset($databaseConfig['options']) ? $databaseConfig['options'] : array();

        // Create connection if we don't have it already
        if (! isset(self::$connections[$name])) {
            $connection = $driver->connect($databaseConfig, $username, $password, $options);

            self::$connections[$name] = $connection;
        }

        return self::$connections[$name];
    }
883644
public function getConnectionManager($name)
    {
        if (!isset($this->connectionManagers[$name])) {
            throw new RuntimeException(sprintf('No connection defined for database "%s". Did you forget to define a connection or is it wrong written?', $name));
        }

        return $this->connectionManagers[$name];
    }
677806
public function getConnection($name)
	{
		if (array_key_exists($name, $this->_connections))
			return $this->_connections[$name];

		return null;
	}
406539
private function loadMenu($name)
    {
        if ($name instanceof Menu) {
            return $name;
        }

        $menu = $this->menuRepository->findOneBy(array('name' => $name));

        if (!$menu) {
            throw new \RuntimeException(sprintf('Unable to load menu "%s"', $name));
        }

        return $menu;
    }
773375
public static function connection($name = 'default')
    {
        $name = $name == 'default' ? self::$config['connection']['default'] : $name;

        return isset(self::$connection[$name])
            ? self::$connection[$name]
            : self::$connection[$name] = self::createForConnection($name);
    }
1160366
public static function factory($name)
    {
        if (!isset(self::$services[$name])) {
            throw new \RuntimeException("The service [$name] don't register.");
        }

        $service = self::$services[$name];

        if (\is_object($service) && method_exists($service, '__invoke')) {
            return $service();
        }

        return $service;
    }
429056
public static function getInstance(string $name): \Swoole\Channel
    {
        if(!static::$isInited)
        {
            throw new \RuntimeException('getInstance failed, ChannelManager is not initialized');
        }
        if(!isset(static::$channels[$name]))
        {
            throw new \RuntimeException(sprintf('GetInstance failed, %s is not found', $name));
        }
        return static::$channels[$name];
    }
754131
public function getRepository($name)
    {
        $storeConfig = $this->config[$name];
        $driver = isset($storeConfig['driver']) ? $storeConfig['driver'] : $name;
        if ($driver instanceof \Closure) {
            $connection = $driver($storeConfig);
        } elseif (method_exists($this, "create" . ucfirst($driver) . 'Store')) {
            $method = "create" . ucfirst($driver) . 'Store';
            $connection = $this->$method($storeConfig);
        } elseif (class_exists($driver)) {
            $connection = new $driver($storeConfig);
        } else {
            throw new \InvalidArgumentException(sprintf(
                'Invalid Cache driver "%s"; must be an defined driver(redis|file) or classname or \Closure',
                $driver
            ));
        }
        return new Repository($connection, $this->config['prefix']);
    }
1309966
public function getDatabase(string $name): Database
    {
        if (!array_key_exists($name, $this->databases)) {
            throw new InvalidArgumentException('Database '.$name.' not added');
        }

        return $this->databases[$name];
    }
319370
public static function get($name)
    {
        if (!isset(self::$config[$name])) {
            $filename = __DIR__.'/../_config/'.$name.'.php';
            if (!file_exists($filename)) {
                throw new \RuntimeException('Error go\\DB config "'.$name.'"');
            }
            self::$config[$name] = include $filename;
        }
        return self::$config[$name];
    }
1251032
public function getConnection($name = ''): QueryBuilderInterface
	{
		// If the parameter is a string, use it as an array index
		if (is_scalar($name) && isset($this->connections[$name]))
		{
			return $this->connections[$name];
		}
		else if (empty($name) && ! empty($this->connections)) // Otherwise, return the last one
		{
			return end($this->connections);
		}

		// You should actually connect before trying to get a connection...
		throw new InvalidArgumentException('The specified connection does not exist');
	}
1294027
public function connection($name = null)
	{
		if (is_array($name)) return $this->multiple($name);

		return $this->resolve($name ?: $this->getDefaultConnection());
	}
237225
protected function getPheanstalk(&$name = null)
    {
        $pheanstalk = $this->locator->getPheanstalk($name);

        if (null === $name) {
            $name = 'default';
        }

        if (null === $pheanstalk) {
            throw new \RuntimeException('Pheanstalk not found: '.$name);
        }

        if (!$pheanstalk->getConnection()->isServiceListening()) {
            throw new \RuntimeException('Pheanstalk not connected: '.$name);
        }

        return $pheanstalk;
    }