{"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/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/server/queue/redis-config.ts#L84-L120","documentation":"Thrown by connectionFromUrl() when the path component of CLAUDE_MEM_REDIS_URL (the database index segment after the host, e.g. redis://h/3) is present but does not parse to a non-negative integer. The db is parsed from pathname.slice(1); a non-numeric or fractional path triggers this. An empty/root path is allowed (db left undefined).","triggerScenarios":"CLAUDE_MEM_REDIS_URL includes a path like /0a, /-1, /1.5, or /db1 where a numeric database index is expected; a trailing slash with text after it.","commonSituations":"Operator includes a path meant for another system (e.g. /my-redis). A copy-paste that appended a label. A negative or fractional value.","solutions":["Use a bare integer for the Redis database index in the URL path, e.g. redis://host:6379/0, or omit the path entirely to use the default.","Remove any non-numeric segment from the URL path.","If you don't need a specific db, drop the path component."],"exampleFix":"// before: export CLAUDE_MEM_REDIS_URL=redis://127.0.0.1:6379/main\n// after: export CLAUDE_MEM_REDIS_URL=redis://127.0.0.1:6379/0","handlingStrategy":"validation","validationCode":"function assertRedisUrlDb(rawUrl: string): void {\n  const parsed = new URL(rawUrl);\n  if (parsed.pathname.length > 1) {\n    const db = Number.parseInt(parsed.pathname.slice(1), 10);\n    if (!Number.isInteger(db) || db < 0) {\n      throw new Error(`Invalid Redis database in CLAUDE_MEM_REDIS_URL: ${parsed.pathname}`);\n    }\n  }\n}","typeGuard":"function hasValidRedisDb(rawUrl: string): boolean {\n  try {\n    const p = new URL(rawUrl).pathname;\n    if (p.length <= 1) return true;\n    const db = Number.parseInt(p.slice(1), 10);\n    return Number.isInteger(db) && db >= 0;\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  conn = connectionFromUrl(rawUrl);\n} catch (error) {\n  if (/Invalid Redis database/.test((error as Error).message)) {\n    console.error('Use a non-negative integer for the Redis db path, e.g. redis://h:6379/0');\n    process.exit(1);\n  }\n  throw error;\n}","preventionTips":["Encode the Redis database as a bare non-negative integer in the URL path, or omit it.","Avoid pasting non-numeric labels into the URL path."],"tags":["config","redis","url","validation"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}