{"record":{"id":"d6e66868ab19c347","repo":"redis/node-redis","slug":"invalid-db-query-parameter","errorCode":null,"errorMessage":"Invalid db query parameter","messagePattern":"Invalid db query parameter","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/client/lib/client/index.ts","lineNumber":580,"sourceCode":"    }\n\n    if (username || password) {\n      parsed.credentialsProvider = {\n        type: 'async-credentials-provider',\n        credentials: async () => (\n          {\n            username: username ? decodeURIComponent(username) : undefined,\n            password: password ? decodeURIComponent(password) : undefined\n          })\n      };\n    }\n\n    if (rawQuery) {\n      const db = new URLSearchParams(rawQuery).get('db');\n      if (db !== null) {\n        const database = Number(db);\n        if (isNaN(database)) {\n          throw new TypeError('Invalid db query parameter');\n        }\n        parsed.database = database;\n      }\n    }\n\n    return parsed;\n  }\n\n  readonly #options: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>;\n  #socket: RedisSocket;\n  readonly #queue: RedisCommandsQueue;\n  #selectedDB = 0;\n  #monitorCallback?: MonitorCallback<TYPE_MAPPING>;\n  private _self = this;\n  private _commandOptions?: CommandOptions<TYPE_MAPPING>;\n  // flag used to annotate that the client\n  // was in a watch transaction when\n  // a topology change occurred","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/redis/node-redis/blob/90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58/packages/client/lib/client/index.ts#L562-L598","documentation":"For unix:// URLs the optional ?db=N query parameter selects the logical database and must be numeric. A non-numeric db value (e.g. ?db=foo) is rejected by Number()/isNaN validation.","triggerScenarios":"Passing unix:///var/run/redis/redis.sock?db=primary or any non-integer db.","commonSituations":"Trying to encode cluster/sentinel hints in the db slot; typo; confusing the db index with a name.","solutions":["Drop the ?db= parameter entirely, or","Use an integer db index (0..15 typically)."],"exampleFix":"// before\ncreateClient({ url: 'unix:///var/run/redis/redis.sock?db=main' });\n\n// after\ncreateClient({ url: 'unix:///var/run/redis/redis.sock?db=0' });","handlingStrategy":"validation","validationCode":"function assertUnixDb(url) {\n  const q = new URL(url, 'unix://x/').searchParams; // parse query loosely\n  const db = q.get('db');\n  if (db != null && !/^\\d+$/.test(db)) {\n    throw new TypeError(`Invalid db query parameter ${db}; expected integer`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use integer db indexes in the ?db= query parameter.","Omit ?db= to default to db 0.","Validate the query string at config load."],"tags":["url","unix-socket","config","validation","database"],"backgroundTag":null,"analyzedSha":"90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58","analyzedAt":"2026-08-11T15:37:21.243Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}