redis/node-redis · error · TypeError

Invalid protocol

Error message

Invalid protocol

What it means

RedisClient.parseURL only accepts the redis: and rediss: schemes. WHATWG URL parses the input first; any other protocol (http:, https:, tcp:, empty, or a bare host that yields no protocol) reaches the protocol check and throws.

Solutions

  1. Use the redis:// or rediss:// scheme.
  2. If you only have host/port, pass them via socket.host and socket.port instead of url.

Example fix

// before
createClient({ url: 'http://redis:6379' });

// after
createClient({ url: 'redis://redis:6379' });
// or
createClient({ socket: { host: 'redis', port: 6379 } });
Defensive patterns

Strategy: validation

Validate before calling

function assertRedisUrl(url) {
  if (!/^redis(s?):\/\/.+/.test(url)) {
    throw new TypeError(`Expected redis:// or rediss:// URL, got ${JSON.stringify(url)}`);
  }
}

Prevention

When it happens

Trigger: Passing 'http://host:6379', 'tcp://host:6379', 'host:6379' (no scheme), or any non-Redis URL to createClient({ url }).

Common situations: Misconfigured environment variable; using a service-discovery URL of the wrong scheme; copy-pasting a connection string from a different system (Postgres/HTTP).

Related errors


AI-assisted analysis of redis/node-redis@90fd0652bc (2026-08-11). Data as JSON: /api/errors/b10338da0f5476a3. Report an issue: GitHub.

Appendix: source

Thrown at packages/client/lib/client/index.ts:493

      return RedisClient.#parseUnixURL(url);
    }

    // https://www.iana.org/assignments/uri-schemes/prov/redis
    const { hostname, port, protocol, username, password, pathname } = new URL(url),
      parsed: AnyRedisClientOptions & {
        socket: Exclude<AnyRedisClientOptions['socket'], undefined> & {
          tls: boolean
        }
      } = {
        socket: {
          // Use net.SocketAddress.parse() once supported.
          host: hostname.replace(/^\[([0-9a-f:]+)\]$/, '$1'),
          tls: false
        }
      };

    if (protocol !== 'redis:' && protocol !== 'rediss:') {
      throw new TypeError('Invalid protocol');
    }

    parsed.socket.tls = protocol === 'rediss:';

    if (port) {
      (parsed.socket as TcpSocketConnectOpts).port = Number(port);
    }

    if (username) {
      parsed.username = decodeURIComponent(username);
    }

    if (password) {
      parsed.password = decodeURIComponent(password);
    }

    if (username || password) {
      parsed.credentialsProvider = {

View on GitHub (pinned to 90fd0652bc)