{"id":"74b26fbee5675206","repo":"redis/node-redis","slug":"tls-socket-option-is-set-to-options-socket-tls","errorCode":null,"errorMessage":"tls socket option is set to ${options.socket.tls} which is mismatch with protocol or the URL ${options.url} passed","messagePattern":"tls socket option is set to (.+?) which is mismatch with protocol or the URL (.+?) passed","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/client/lib/client/index.ts","lineNumber":457,"sourceCode":"    };\n  }\n\n  static create<\n    M extends RedisModules = {},\n    F extends RedisFunctions = {},\n    S extends RedisScripts = {},\n    RESP extends RespVersions = 3,\n    TYPE_MAPPING extends TypeMapping = {}\n  >(this: void, options?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>) {\n    return RedisClient.factory(options)(options);\n  }\n\n  static parseOptions<O extends AnyRedisClientOptions>(options: O): O {\n    if (options?.url) {\n      const parsed = RedisClient.parseURL(options.url);\n      if (options.socket) {\n        if (options.socket.tls !== undefined && options.socket.tls !== parsed.socket.tls) {\n          throw new TypeError(`tls socket option is set to ${options.socket.tls} which is mismatch with protocol or the URL ${options.url} passed`)\n        }\n        parsed.socket = Object.assign(options.socket, parsed.socket);\n      }\n\n      Object.assign(options, parsed);\n    }\n    return options;\n  }\n\n  static parseURL(url: string): AnyRedisClientOptions & {\n    socket: Exclude<AnyRedisClientOptions['socket'], undefined> & {\n      tls: boolean\n    }\n  } {\n    // unix:// URIs use a non-special scheme; WHATWG URL refuses to parse an\n    // authority (e.g. `user:pass@`) without a host, so handle it separately.\n    if (url.startsWith('unix:')) {\n      return RedisClient.#parseUnixURL(url);","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/redis/node-redis/blob/bb5beb56578573910e2ee8f39681edc214c41398/packages/client/lib/client/index.ts#L439-L475","documentation":"During parseOptions, when both `options.url` and `options.socket` are provided, the client checks that any explicit `socket.tls` agrees with the URL's scheme (rediss:// => tls true, redis:// => tls false). A mismatch means the developer asked for two contradictory things (e.g. a rediss:// URL but socket.tls=false, or redis:// with socket.tls=true), which would produce a confusing TLS handshake failure later — so it fails fast with a TypeError showing both values.","triggerScenarios":"`createClient({ url: 'rediss://host:6379', socket: { tls: false } })`; `createClient({ url: 'redis://host:6379', socket: { tls: true } })`; merging a tls:false default socket config with a rediss:// URL from env.","commonSituations":"Layered config (base config sets socket.tls, env provides the URL) where the two disagree; copy-paste from an example that hard-coded socket.tls; migrating from redis:// to rediss:// without removing an explicit socket.tls override.","solutions":["Make TLS consistent: use rediss:// together with socket.tls omitted (it is derived from the URL), or set socket.tls to match the scheme.","Prefer specifying TLS via the URL scheme only and drop the explicit socket.tls to avoid the conflict.","Centralize connection config so the URL scheme and socket.tls cannot drift apart."],"exampleFix":"// before\ncreateClient({ url: 'rediss://host:6379', socket: { tls: false } });\n\n// after\ncreateClient({ url: 'rediss://host:6379' });","handlingStrategy":"validation","validationCode":"function resolveRedisOptions(raw) {\n  if (raw.url && raw.socket?.tls !== undefined) {\n    const schemeTls = raw.url.startsWith('rediss://');\n    if (raw.socket.tls !== schemeTls) {\n      throw new TypeError('socket.tls conflicts with the URL scheme');\n    }\n  }\n  return raw;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Specify TLS via the URL scheme only (rediss://) and omit socket.tls.","Centralize connection config so scheme and socket.tls cannot drift.","When migrating redis:// to rediss://, remove explicit socket.tls overrides."],"tags":["config","tls","url","validation"],"analyzedSha":"bb5beb56578573910e2ee8f39681edc214c41398","analyzedAt":"2026-08-03T19:09:15.686Z","schemaVersion":2}