{"record":{"id":"38bfdba434c6e214","repo":"thedotmack/claude-mem","slug":"invalid-redis-database-in-claude-mem-redis-url","errorCode":null,"errorMessage":"Invalid Redis database in CLAUDE_MEM_REDIS_URL: ${parsed.pathname}","messagePattern":"Invalid Redis database in CLAUDE_MEM_REDIS_URL: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/server/queue/redis-config.ts","lineNumber":102,"sourceCode":"  return {\n    host,\n    port,\n    maxRetriesPerRequest: null,\n    connectTimeout: 1000,\n    lazyConnect: true,\n  };\n}\n\nfunction connectionFromUrl(rawUrl: string): RedisOptions {\n  const parsed = new URL(rawUrl);\n  if (parsed.protocol !== 'redis:' && parsed.protocol !== 'rediss:') {\n    throw new Error('CLAUDE_MEM_REDIS_URL must use redis:// or rediss://');\n  }\n  const db = parsed.pathname.length > 1\n    ? Number.parseInt(parsed.pathname.slice(1), 10)\n    : undefined;\n  if (db !== undefined && (!Number.isInteger(db) || db < 0)) {\n    throw new Error(`Invalid Redis database in CLAUDE_MEM_REDIS_URL: ${parsed.pathname}`);\n  }\n  return {\n    host: parsed.hostname || '127.0.0.1',\n    port: parsed.port ? Number.parseInt(parsed.port, 10) : 6379,\n    username: parsed.username ? decodeURIComponent(parsed.username) : undefined,\n    password: parsed.password ? decodeURIComponent(parsed.password) : undefined,\n    db,\n    tls: parsed.protocol === 'rediss:' ? {} : undefined,\n    maxRetriesPerRequest: null,\n    connectTimeout: 1000,\n    lazyConnect: true,\n  };\n}\n\nfunction describeUrlHost(rawUrl: string): { host: string; port: number } {\n  const parsed = new URL(rawUrl);\n  return {\n    host: parsed.hostname || '127.0.0.1',","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/server/queue/redis-config.ts#L84-L120","documentation":"Thrown by connectionFromUrl when the path portion of CLAUDE_MEM_REDIS_URL is supposed to select the Redis database number but does not parse to a non-negative integer. In redis://host:port/db, the db segment must be a valid integer >= 0 (e.g. /0, /1); anything else — non-numeric text, negative numbers, multi-segment paths — is rejected so a wrong database index never reaches the client.","triggerScenarios":"CLAUDE_MEM_REDIS_URL ending in /abc, /-1, /0/extra (pathname '/0/extra' fails parseInt), /mydb, or a trailing path like /prefix. Any URL where parsed.pathname.length > 1 and the slice after '/' is not a clean non-negative integer throws.","commonSituations":"Appending a key prefix or instance name to the URL out of habit (common with Cloudflare/Upstash style endpoints); copying a Postgres-style URL with a database name like /postgres; leaving a trailing slash plus garbage; misreading the db number as a name ('sessions' instead of '0').","solutions":["Use a numeric database index in the path: redis://host:6379/0","Remove the path entirely (redis://host:6379) to use the client default database","Move any logical naming (e.g. key prefixes) to the appropriate prefix setting (see sanitizePrefix/CLAUDE_MEM queue prefix config), not the URL path","Strip extra path segments so the URL has at most one /<integer> after the port"],"exampleFix":"// before (.env)\nCLAUDE_MEM_REDIS_URL=redis://localhost:6379/claude-mem\n// after\nCLAUDE_MEM_REDIS_URL=redis://localhost:6379/0","handlingStrategy":"validation","validationCode":"const url = process.env.CLAUDE_MEM_REDIS_URL;\nif (url) {\n  const path = new URL(url).pathname;\n  if (path.length > 1) {\n    const db = Number(path.slice(1));\n    if (!Number.isInteger(db) || db < 0) {\n      throw new Error(`Redis URL path must be a numeric db index (e.g. /0); got \"${path}\"`);\n    }\n  }\n}","typeGuard":"function hasValidRedisDbPath(url: string): boolean {\n  const path = new URL(url).pathname;\n  if (path.length <= 1) return true;\n  const db = Number(path.slice(1));\n  return Number.isInteger(db) && db >= 0;\n}","tryCatchPattern":"try {\n  const config = getRedisQueueConfig();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Invalid Redis database in CLAUDE_MEM_REDIS_URL')) {\n    console.error('The URL path must be a numeric database index like /0 — use a key-prefix setting for names instead');\n  }\n  throw err;\n}","preventionTips":["Remember redis URL paths are numeric DB indexes, not database names like Postgres","Put logical names/prefixes in dedicated prefix config, never in the URL path","Omit the path entirely to use the default database","Copy exact connection strings from provider docs rather than hand-editing paths"],"tags":["configuration","redis","url","validation"],"backgroundTag":"invalid-url-format","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}