thedotmack/claude-mem · error

Invalid Redis database in CLAUDE_MEM_REDIS_URL: ${parsed.pat

Error message

Invalid Redis database in CLAUDE_MEM_REDIS_URL: ${parsed.pathname}

What it means

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).

Source

Thrown at src/server/queue/redis-config.ts:102

  return {
    host,
    port,
    maxRetriesPerRequest: null,
    connectTimeout: 1000,
    lazyConnect: true,
  };
}

function connectionFromUrl(rawUrl: string): RedisOptions {
  const parsed = new URL(rawUrl);
  if (parsed.protocol !== 'redis:' && parsed.protocol !== 'rediss:') {
    throw new Error('CLAUDE_MEM_REDIS_URL must use redis:// or rediss://');
  }
  const db = parsed.pathname.length > 1
    ? Number.parseInt(parsed.pathname.slice(1), 10)
    : undefined;
  if (db !== undefined && (!Number.isInteger(db) || db < 0)) {
    throw new Error(`Invalid Redis database in CLAUDE_MEM_REDIS_URL: ${parsed.pathname}`);
  }
  return {
    host: parsed.hostname || '127.0.0.1',
    port: parsed.port ? Number.parseInt(parsed.port, 10) : 6379,
    username: parsed.username ? decodeURIComponent(parsed.username) : undefined,
    password: parsed.password ? decodeURIComponent(parsed.password) : undefined,
    db,
    tls: parsed.protocol === 'rediss:' ? {} : undefined,
    maxRetriesPerRequest: null,
    connectTimeout: 1000,
    lazyConnect: true,
  };
}

function describeUrlHost(rawUrl: string): { host: string; port: number } {
  const parsed = new URL(rawUrl);
  return {
    host: parsed.hostname || '127.0.0.1',

View on GitHub (pinned to d768ba3643)

Solutions

  1. 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.
  2. Remove any non-numeric segment from the URL path.
  3. If you don't need a specific db, drop the path component.

Example fix

// before: export CLAUDE_MEM_REDIS_URL=redis://127.0.0.1:6379/main
// after: export CLAUDE_MEM_REDIS_URL=redis://127.0.0.1:6379/0
Defensive patterns

Strategy: validation

Validate before calling

function assertRedisUrlDb(rawUrl: string): void {
  const parsed = new URL(rawUrl);
  if (parsed.pathname.length > 1) {
    const db = Number.parseInt(parsed.pathname.slice(1), 10);
    if (!Number.isInteger(db) || db < 0) {
      throw new Error(`Invalid Redis database in CLAUDE_MEM_REDIS_URL: ${parsed.pathname}`);
    }
  }
}

Type guard

function hasValidRedisDb(rawUrl: string): boolean {
  try {
    const p = new URL(rawUrl).pathname;
    if (p.length <= 1) return true;
    const db = Number.parseInt(p.slice(1), 10);
    return Number.isInteger(db) && db >= 0;
  } catch {
    return false;
  }
}

Try / catch

try {
  conn = connectionFromUrl(rawUrl);
} catch (error) {
  if (/Invalid Redis database/.test((error as Error).message)) {
    console.error('Use a non-negative integer for the Redis db path, e.g. redis://h:6379/0');
    process.exit(1);
  }
  throw error;
}

Prevention

When it happens

Trigger: 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.

Common situations: Operator includes a path meant for another system (e.g. /my-redis). A copy-paste that appended a label. A negative or fractional value.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d768ba3643 (2026-08-12). Data as JSON: /api/errors/38bfdba434c6e214. Report an issue: GitHub.