Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Float64Map #564

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions redis/reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,32 @@ func Int64Map(result interface{}, err error) (map[string]int64, error) {
return m, nil
}

// Float64Map is a helper that converts an array of strings (alternating key, value)
// into a map[string]Float64Map. The HGETALL commands return replies in this format.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// into a map[string]Float64Map. The HGETALL commands return replies in this format.
// into a map[string]float64. The HGETALL commands return replies in this format.

// Requires an even number of values in result.
func Float64Map(result interface{}, err error) (map[string]float64, error) {
values, err := Values(result, err)
if err != nil {
return nil, err
}
if len(values)%2 != 0 {
return nil, errors.New("redigo: Float64Map expects even number of values result")
}
m := make(map[string]float64, len(values)/2)
for i := 0; i < len(values); i += 2 {
key, ok := values[i].([]byte)
if !ok {
return nil, errors.New("redigo: Float64Map key not a bulk string value")
}
value, err := Float64(values[i+1], nil)
if err != nil {
return nil, err
}
m[string(key)] = value
}
return m, nil
}

// Positions is a helper that converts an array of positions (lat, long)
// into a [][2]float64. The GEOPOS command returns replies in this format.
func Positions(result interface{}, err error) ([]*[2]float64, error) {
Expand Down