go-redis/redis · error
redis: unexpected type=%T for Float64
Error message
redis: unexpected type=%T for Float64
What it means
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.
Source
Thrown at command.go:751
}
}
func (cmd *Cmd) Float64() (float64, error) {
cmd.await()
if cmd.err != nil {
return 0, cmd.err
}
return toFloat64(cmd.val)
}
func toFloat64(val interface{}) (float64, error) {
switch val := val.(type) {
case int64:
return float64(val), nil
case string:
return strconv.ParseFloat(val, 64)
default:
err := fmt.Errorf("redis: unexpected type=%T for Float64", val)
return 0, err
}
}
func (cmd *Cmd) Bool() (bool, error) {
cmd.await()
if cmd.err != nil {
return false, cmd.err
}
return toBool(cmd.val)
}
func toBool(val interface{}) (bool, error) {
switch val := val.(type) {
case bool:
return val, nil
case int64:
return val != 0, nilView on GitHub (pinned to 36d97525cd)
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.
Example fix
// before f, err := client.Do(ctx, "GEODIST", "g", "a", "b").Float64() // after d, err := client.GeoDist(ctx, "g", "a", "b", "m").Result()
Defensive patterns
Strategy: type-guard
Type guard
func asFloat64(cmd *redis.Cmd) (float64, error) {
if err := cmd.Err(); err != nil { return 0, err }
switch v := cmd.Val().(type) {
case int64:
return float64(v), nil
case string:
return strconv.ParseFloat(v, 64)
default:
return 0, fmt.Errorf("not a float64: %T", v)
}
} Try / catch
f, err := cmd.Float64()
if err != nil && strings.Contains(err.Error(), "unexpected type") {
// switch to a typed float command
} Prevention
- Use FloatCmd-returning methods (ZScore, GeoDist) for float replies.
- Type-switch on Result() for raw Do replies.
- Handle redis.Nil before coercing.
When it happens
Trigger: 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.
Common situations: Generic Cmd from Do mis-typed; module reply shape change across versions; wrong accessor for a sorted-set command that returns members+scores.
Related errors
- redis: unexpected type=%T for String
- redis: unexpected type=%T for Int
- redis: unexpected type=%T for Int64
- redis: unexpected type=%T for Uint64
- redis: unexpected type=%T for Float32
AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06).
Data as JSON: /data/errors/e5611b40b2ba5a23.json.
Report an issue: GitHub.