{"id":"b10338da0f5476a3","repo":"redis/node-redis","slug":"invalid-protocol","errorCode":null,"errorMessage":"Invalid protocol","messagePattern":"Invalid protocol","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/client/lib/client/index.ts","lineNumber":493,"sourceCode":"      return RedisClient.#parseUnixURL(url);\n    }\n\n    // https://www.iana.org/assignments/uri-schemes/prov/redis\n    const { hostname, port, protocol, username, password, pathname } = new URL(url),\n      parsed: AnyRedisClientOptions & {\n        socket: Exclude<AnyRedisClientOptions['socket'], undefined> & {\n          tls: boolean\n        }\n      } = {\n        socket: {\n          // Use net.SocketAddress.parse() once supported.\n          host: hostname.replace(/^\\[([0-9a-f:]+)\\]$/, '$1'),\n          tls: false\n        }\n      };\n\n    if (protocol !== 'redis:' && protocol !== 'rediss:') {\n      throw new TypeError('Invalid protocol');\n    }\n\n    parsed.socket.tls = protocol === 'rediss:';\n\n    if (port) {\n      (parsed.socket as TcpSocketConnectOpts).port = Number(port);\n    }\n\n    if (username) {\n      parsed.username = decodeURIComponent(username);\n    }\n\n    if (password) {\n      parsed.password = decodeURIComponent(password);\n    }\n\n    if (username || password) {\n      parsed.credentialsProvider = {","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/redis/node-redis/blob/bb5beb56578573910e2ee8f39681edc214c41398/packages/client/lib/client/index.ts#L475-L511","documentation":"parseURL uses the WHATWG URL parser to read a redis/rediss URI; if the scheme is neither 'redis:' nor 'rediss:' it throws 'Invalid protocol'. Only those two IANA-registered schemes map to a Redis socket; anything else (http:, postgres://, mongodb://, typo like 'redi://') is rejected at parse time.","triggerScenarios":"`createClient({ url: 'http://host:6379' })`; a typo'd scheme ('redi://', 'redsi://'); passing a non-Redis connection string that happens to live in the same config; an env var containing a generic database URL.","commonSituations":"Wrong env var wired to the Redis client; copy-paste from another service's connection string; a leading/trailing space or stray character breaking the scheme; a service-discovery URL using a custom scheme.","solutions":["Use a URL beginning with 'redis://' (plain) or 'rediss://' (TLS).","Double-check the env var name and value; strip whitespace.","If your service discovery returns a custom scheme, map it to redis:// or rediss:// before passing to createClient."],"exampleFix":"// before\ncreateClient({ url: process.env.DATABASE_URL }); // 'postgres://...'\n\n// after\ncreateClient({ url: process.env.REDIS_URL }); // 'redis://...'","handlingStrategy":"validation","validationCode":"function assertRedisUrl(url) {\n  if (!/^rediss?:\\/\\//.test(url.trim())) {\n    throw new TypeError(`Expected redis:// or rediss:// URL, got ${url}`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wire the REDIS_URL env var (not a generic DATABASE_URL) to the Redis client.","Validate the scheme before passing to createClient.","Strip whitespace from env-provided URLs."],"tags":["config","url","validation"],"analyzedSha":"bb5beb56578573910e2ee8f39681edc214c41398","analyzedAt":"2026-08-03T19:09:15.686Z","schemaVersion":2}