{"id":"bba5ddfd048667c2","repo":"go-redis/redis","slug":"redis-invalid-s-number-s","errorCode":null,"errorMessage":"redis: invalid %s number: %s","messagePattern":"redis: invalid (.+?) number: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"options.go","lineNumber":782,"sourceCode":"}\n\nfunc (o *queryOptions) strings(name string) []string {\n\tvs := o.q[name]\n\tdelete(o.q, name)\n\treturn vs\n}\n\nfunc (o *queryOptions) int(name string) int {\n\ts := o.string(name)\n\tif s == \"\" {\n\t\treturn 0\n\t}\n\ti, err := strconv.Atoi(s)\n\tif err == nil {\n\t\treturn i\n\t}\n\tif o.err == nil {\n\t\to.err = fmt.Errorf(\"redis: invalid %s number: %s\", name, err)\n\t}\n\treturn 0\n}\n\nfunc (o *queryOptions) duration(name string) time.Duration {\n\ts := o.string(name)\n\tif s == \"\" {\n\t\treturn 0\n\t}\n\t// try plain number first\n\tif i, err := strconv.Atoi(s); err == nil {\n\t\tif i <= 0 {\n\t\t\t// disable timeouts\n\t\t\treturn -1\n\t\t}\n\t\treturn time.Duration(i) * time.Second\n\t}\n\tdur, err := time.ParseDuration(s)","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/options.go#L764-L800","documentation":"Recorded on the queryOptions error slot by queryOptions.int when a query parameter expected to be an integer fails strconv.Atoi. The placeholder is the parameter name (e.g. max_retries, pool_size); the error is surfaced at the end of setupConnParams. Only the first failing parameter is reported.","triggerScenarios":"A redis:// or rediss:// URL with a query parameter like ?max_retries=abc, ?pool_size=1.5, or ?protocol=three. Any integer-typed option fed a non-integer string.","commonSituations":"Typing a unit suffix on an int field (?pool_size=10x), a float value, or a stray character from templating/env substitution.","solutions":["Provide a clean decimal integer for the named parameter.","Remove the parameter to accept the go-redis default.","Run the URL through url.Parse and validate each known int param before constructing the client."],"exampleFix":"// before\nopt, err := redis.ParseURL(\"redis://localhost:6379/?max_retries=three\")\n// after\nopt, err := redis.ParseURL(\"redis://localhost:6379/?max_retries=3\")","handlingStrategy":"validation","validationCode":"func validIntParam(s string) bool { _, err := strconv.Atoi(s); return err == nil }","typeGuard":null,"tryCatchPattern":"if _, err := redis.ParseURL(raw); err != nil { /* surface the named param in user feedback */ }","preventionTips":["Keep integer query params to plain decimal digits.","Generate URLs from typed config, not string concatenation.","Document which params are ints vs durations vs bools for ops teams."],"tags":["config","url","validation"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}