{"record":{"id":"5dfc3eb7aaf8b350","repo":"symfony/symfony","slug":"invalid-redis-dsn","errorCode":null,"errorMessage":"Invalid Redis DSN.","messagePattern":"Invalid Redis DSN\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Component/Cache/Traits/RedisTrait.php","lineNumber":124,"sourceCode":"        $auth = null;\n        $params = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:(?<user>[^:@]*+):)?(?<password>[^@]*+)@)?#', static function ($m) use (&$auth) {\n            if (isset($m['password'])) {\n                if (\\in_array($m['user'], ['', 'default'], true)) {\n                    $auth = rawurldecode($m['password']);\n                } else {\n                    $auth = [rawurldecode($m['user']), rawurldecode($m['password'])];\n                }\n\n                if ('' === $auth) {\n                    $auth = null;\n                }\n            }\n\n            return 'file:'.($m[1] ?? '');\n        }, $dsn);\n\n        if (false === $params = parse_url($params)) {\n            throw new InvalidArgumentException('Invalid Redis DSN.');\n        }\n\n        $query = $hosts = [];\n\n        $tls = 'rediss' === $scheme || 'valkeys' === $scheme;\n        $tcpScheme = $tls ? 'tls' : 'tcp';\n\n        if (isset($params['query'])) {\n            parse_str($params['query'], $query);\n\n            if (isset($query['host'])) {\n                if (!\\is_array($hosts = $query['host'])) {\n                    throw new InvalidArgumentException('Invalid Redis DSN: query parameter \"host\" must be an array.');\n                }\n                foreach ($hosts as $host => $parameters) {\n                    if (\\is_string($parameters)) {\n                        parse_str($parameters, $parameters);\n                    }","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/symfony/symfony/blob/3b11ffbe2520436b0951974d1993dc2144f91dd3/src/Symfony/Component/Cache/Traits/RedisTrait.php#L106-L142","documentation":"Thrown by RedisAdapter::createConnection() when parse_url() fails on the normalised DSN, returning false. Before parsing, the method rewrites the scheme to 'file:' and extracts auth credentials via preg_replace_callback; if the resulting string is not a parseable URL, parse_url returns false and the DSN is deemed invalid. This is a catch-all for malformed DSNs that passed the scheme check but are structurally broken.","triggerScenarios":"A DSN like 'redis://' with nothing else (no host), a DSN with illegal characters that survive the scheme/auth rewrite, or a severely malformed string. Also possible with certain malformed unix socket DSNs or unencoded credentials containing reserved characters.","commonSituations":"Env var truncated or set to a placeholder like 'redis://'. Unencoded special characters in the password (e.g. '@' or ':' not percent-encoded). Copy-paste error leaving stray characters. DSN built by string concatenation with a missing part.","solutions":["Provide a complete, well-formed DSN: 'redis://host:6379' or 'redis:///var/run/redis.sock'.","Percent-encode any special characters in the username/password portion of the DSN.","Check the environment variable is fully populated (not truncated).","Log or dump the DSN (without secrets) during debugging to inspect its actual value."],"exampleFix":"// before\n$redis = RedisAdapter::createConnection(getenv('REDIS_URL')); // REDIS_URL='redis://'\n\n// after - set a complete DSN\n// REDIS_URL='redis://127.0.0.1:6379'\n$redis = RedisAdapter::createConnection(getenv('REDIS_URL'));","handlingStrategy":"validation","validationCode":"// Validate the DSN parses after scheme normalisation.\n$test = preg_replace('#^(redis|rediss|valkey|valkeys)s?:#', 'file:', $dsn);\nif (false === parse_url($test)) {\n    throw new \\InvalidArgumentException('Redis DSN is malformed: ' . $dsn);\n}\n$redis = RedisAdapter::createConnection($dsn);","typeGuard":null,"tryCatchPattern":"try {\n    $redis = RedisAdapter::createConnection($dsn);\n} catch (\\Symfony\\Component\\Cache\\Exception\\InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'Invalid Redis DSN')) {\n        // inspect the env var; likely truncated or unencoded credentials\n        throw new \\RuntimeException('Redis DSN invalid - check REDIS_URL', 0, $e);\n    }\n}","preventionTips":["Provide a complete DSN with a host (redis://host:6379).","Percent-encode special characters in DSN credentials.","Ensure env vars are not truncated; log the DSN length during debugging.","Unit-test DSN construction if you build it dynamically."],"tags":["cache","redis","dsn","configuration","invalid-argument","symfony"],"backgroundTag":null,"analyzedSha":"3b11ffbe2520436b0951974d1993dc2144f91dd3","analyzedAt":"2026-08-11T22:13:02.001Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}