{"record":{"id":"756cc3bff6171785","repo":"symfony/symfony","slug":"invalid-redis-dsn-it-does-not-start-with-redis-s","errorCode":null,"errorMessage":"Invalid Redis DSN: it does not start with \"redis[s]:\" nor \"valkey[s]:\".","messagePattern":"Invalid Redis DSN: it does not start with \"redis\\[s\\]:\" nor \"valkey\\[s\\]:\"\\.","errorType":"exception","errorClass":"Symfony\\Component\\Cache\\Exception\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Component/Cache/Traits/RedisTrait.php","lineNumber":99,"sourceCode":"     * Example DSN:\n     *   - redis://localhost\n     *   - redis://example.com:1234\n     *   - redis://secret@example.com/13\n     *   - redis:///var/run/redis.sock\n     *   - redis://secret@/var/run/redis.sock/13\n     *\n     * @param array $options See self::$defaultConnectionOptions\n     *\n     * @throws InvalidArgumentException when the DSN is invalid\n     */\n    public static function createConnection(#[\\SensitiveParameter] string $dsn, array $options = []): \\Redis|\\RedisArray|\\RedisCluster|\\Predis\\ClientInterface|Relay|RelayCluster\n    {\n        $scheme = match (true) {\n            str_starts_with($dsn, 'redis:') => 'redis',\n            str_starts_with($dsn, 'rediss:') => 'rediss',\n            str_starts_with($dsn, 'valkey:') => 'valkey',\n            str_starts_with($dsn, 'valkeys:') => 'valkeys',\n            default => throw new InvalidArgumentException('Invalid Redis DSN: it does not start with \"redis[s]:\" nor \"valkey[s]:\".'),\n        };\n\n        if (!\\extension_loaded('redis') && !\\extension_loaded('relay') && !class_exists(\\Predis\\Client::class)) {\n            throw new CacheException('Cannot find the \"redis\" extension nor the \"relay\" extension nor the \"predis/predis\" package.');\n        }\n\n        $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                }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/symfony/symfony/blob/698e28026c22cf35d032cdb6e800db48b1535790/src/Symfony/Component/Cache/Traits/RedisTrait.php#L81-L117","documentation":"createConnection() begins by detecting the DSN scheme with a match expression. Only redis:, rediss:, valkey:, valkeys: are recognised; anything else is rejected immediately as a clearly invalid Redis DSN rather than producing a confusing parse failure later.","triggerScenarios":"Passing 'memcached://localhost'; a typo like 'reddis://' or 'rediss' (no colon); an env var that resolved to an empty string; passing a host without a scheme ('localhost:6379').","commonSituations":"Wrong REDIS_URL scheme; copy-pasted a Doctrine cache URL expecting memcached; trailing-space or BOM in env var stripping the scheme.","solutions":["Prefix the DSN with a supported scheme: redis://, rediss:// (TLS), valkey://, valkeys://.","Validate the env value at boot: if (!preg_match('#^redis[s]?://|^valkey[s]?://#', $dsn)) fail loud.","Check for accidental whitespace: trim($dsn)."],"exampleFix":"// before\nRedisAdapter::createConnection(getenv('REDIS_URL')); // 'localhost:6379'\n\n// after\nRedisAdapter::createConnection('redis://'.trim(getenv('REDIS_URL')));","handlingStrategy":"validation","validationCode":"$dsn = trim((string) $dsn);\nif (!preg_match('#^redis[s]?://|^valkey[s]?://#', $dsn)) {\n    throw new \\InvalidArgumentException('REDIS_URL must start with redis[s]:/valkey[s]:');\n}","typeGuard":"function validRedisScheme(string $dsn): bool {\n    return (bool) preg_match('#^redis[s]?://|^valkey[s]?://#', $dsn);\n}","tryCatchPattern":null,"preventionTips":["Always include a supported scheme in REDIS_URL.","Trim env vars before use.","Fail fast at boot with an explicit scheme check."],"tags":["redis","dsn","validation"],"analyzedSha":"698e28026c22cf35d032cdb6e800db48b1535790","analyzedAt":"2026-08-06T23:40:49.025Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}