{"id":"e5611b40b2ba5a23","repo":"go-redis/redis","slug":"redis-unexpected-type-t-for-float64","errorCode":null,"errorMessage":"redis: unexpected type=%T for Float64","messagePattern":"redis: unexpected type=%T for Float64","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":751,"sourceCode":"\t}\n}\n\nfunc (cmd *Cmd) Float64() (float64, error) {\n\tcmd.await()\n\tif cmd.err != nil {\n\t\treturn 0, cmd.err\n\t}\n\treturn toFloat64(cmd.val)\n}\n\nfunc toFloat64(val interface{}) (float64, error) {\n\tswitch val := val.(type) {\n\tcase int64:\n\t\treturn float64(val), nil\n\tcase string:\n\t\treturn strconv.ParseFloat(val, 64)\n\tdefault:\n\t\terr := fmt.Errorf(\"redis: unexpected type=%T for Float64\", val)\n\t\treturn 0, err\n\t}\n}\n\nfunc (cmd *Cmd) Bool() (bool, error) {\n\tcmd.await()\n\tif cmd.err != nil {\n\t\treturn false, cmd.err\n\t}\n\treturn toBool(cmd.val)\n}\n\nfunc toBool(val interface{}) (bool, error) {\n\tswitch val := val.(type) {\n\tcase bool:\n\t\treturn val, nil\n\tcase int64:\n\t\treturn val != 0, nil","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/command.go#L733-L769","documentation":"Returned by toFloat64 (command.go:744) when Cmd.Float64() is called on a reply value that is neither int64 nor string. int64 is cast to float64; string is parsed via strconv.ParseFloat(..., 64); any other concrete type yields this error. Usually means the accessor was used against a reply that did not carry a single float scalar.","triggerScenarios":"Calling Float64() on a raw Cmd holding an array (e.g. Do of a command that returns a list of scores); calling Float64() on a nil/empty reply without a prior nil-check; using Float64() where a FloatSliceCmd accessor is required.","commonSituations":"Generic Cmd from Do mis-typed; module reply shape change across versions; wrong accessor for a sorted-set command that returns members+scores.","solutions":["Use the typed command (ZScore/GeoDist → FloatCmd; ZDiffWithScores → ZSliceCmd).","Type-switch on cmd.Result() when using Do.","Handle redis.Nil before coercing the value."],"exampleFix":"// before\nf, err := client.Do(ctx, \"GEODIST\", \"g\", \"a\", \"b\").Float64()\n\n// after\nd, err := client.GeoDist(ctx, \"g\", \"a\", \"b\", \"m\").Result()","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func asFloat64(cmd *redis.Cmd) (float64, error) {\n    if err := cmd.Err(); err != nil { return 0, err }\n    switch v := cmd.Val().(type) {\n    case int64:\n        return float64(v), nil\n    case string:\n        return strconv.ParseFloat(v, 64)\n    default:\n        return 0, fmt.Errorf(\"not a float64: %T\", v)\n    }\n}","tryCatchPattern":"f, err := cmd.Float64()\nif err != nil && strings.Contains(err.Error(), \"unexpected type\") {\n    // switch to a typed float command\n}","preventionTips":["Use FloatCmd-returning methods (ZScore, GeoDist) for float replies.","Type-switch on Result() for raw Do replies.","Handle redis.Nil before coercing."],"tags":["command","type-conversion","reply-parsing","api-misuse"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}