{"id":"79ff6b47335f663c","repo":"go-redis/redis","slug":"redis-invalid-url-scheme-s","errorCode":null,"errorMessage":"redis: invalid URL scheme: %s","messagePattern":"redis: invalid URL scheme: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"options.go","lineNumber":679,"sourceCode":"//\t\tAddr:        \"localhost:6789\",\n//\t\tDB:          1,               // path \"/3\" was overridden by \"&db=1\"\n//\t\tDialTimeout: 3 * time.Second, // no time unit = seconds\n//\t\tReadTimeout: 6 * time.Second,\n//\t\tMaxRetries:  2,\n//\t}\nfunc ParseURL(redisURL string) (*Options, error) {\n\tu, err := url.Parse(redisURL)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tswitch u.Scheme {\n\tcase \"redis\", \"rediss\":\n\t\treturn setupTCPConn(u)\n\tcase \"unix\":\n\t\treturn setupUnixConn(u)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"redis: invalid URL scheme: %s\", u.Scheme)\n\t}\n}\n\nfunc setupTCPConn(u *url.URL) (*Options, error) {\n\to := &Options{Network: \"tcp\"}\n\n\to.Username, o.Password = getUserPassword(u)\n\n\th, p := getHostPortWithDefaults(u)\n\to.Addr = net.JoinHostPort(h, p)\n\n\tf := strings.FieldsFunc(u.Path, func(r rune) bool {\n\t\treturn r == '/'\n\t})\n\tswitch len(f) {\n\tcase 0:\n\t\to.DB = 0\n\tcase 1:","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/options.go#L661-L697","documentation":"Returned by ParseURL (standalone client) when the URL scheme is not one of redis, rediss (TLS), or unix. ParseURL switches on u.Scheme and falls through to this error for anything else, including missing schemes (empty string) or typos like 'rediss://'.","triggerScenarios":"Calling redis.ParseURL with a string whose scheme is unrecognised, e.g. \"http://...\", \"localhost:6379\" (no scheme), or a scheme with a typo.","commonSituations":"Forgetting the redis:// prefix and passing a bare host:port, copy-pasting a URL from another driver (postgres://, memcached://), or an env var (REDIS_URL) populated with the wrong format.","solutions":["Prefix the address with redis:// (or rediss:// for TLS, unix:// for sockets).","If you only have host:port, construct *redis.Options directly with Addr instead of ParseURL.","Sanitise REDIS_URL at startup and fail fast with a clear message if the scheme is wrong."],"exampleFix":"// before\nopt, err := redis.ParseURL(\"localhost:6379/0\")\n// after\nopt, err := redis.ParseURL(\"redis://localhost:6379/0\")","handlingStrategy":"validation","validationCode":"func validRedisScheme(rawURL string) bool {\n    u, err := url.Parse(rawURL)\n    if err != nil { return false }\n    switch u.Scheme { case \"redis\", \"rediss\", \"unix\": return true }\n    return false\n}","typeGuard":"func isRedisURL(rawURL string) bool {\n    u, err := url.Parse(rawURL); if err != nil { return false }\n    return u.Scheme == \"redis\" || u.Scheme == \"rediss\" || u.Scheme == \"unix\"\n}","tryCatchPattern":"opt, err := redis.ParseURL(raw)\nif err != nil { /* fall back to redis.Options{Addr: host} or fail fast */ }","preventionTips":["Always include the scheme in REDIS_URL.","Prefer redis.Options{Addr: ...} when you only have host:port.","Validate REDIS_URL at startup, not on first command."],"tags":["config","url","validation"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}