protected function getRandomConnection(): ?Client
    {
        if ($this->pool) {
            return $this->pool[\array_rand($this->pool)];
        }

        if ($this->hosts) {
            $key = \array_rand($this->hosts);
            $connectionID = $this->hosts[$key];
            unset($key);

            return $this->createConnection($connectionID);
        }

        return null;
    }