1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-14 01:21:30 +03:00

support geopos command

This commit is contained in:
Sergey Shcherbina
2016-08-22 02:32:06 +05:00
parent 909c26e76c
commit ac1c5e46f9
3 changed files with 97 additions and 0 deletions

View File

@ -273,6 +273,48 @@ func newGeoLocationSliceParser(q *GeoRadiusQuery) proto.MultiBulkParse {
}
}
func newGeoPositionParser() proto.MultiBulkParse {
return func(rd *proto.Reader, n int64) (interface{}, error) {
var pos GeoPosition
var err error
pos.Longitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
pos.Latitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
return &pos, nil
}
}
func newGeoPositionSliceParser() proto.MultiBulkParse {
return func(rd *proto.Reader, n int64) (interface{}, error) {
positions := make([]*GeoPosition, 0, n)
for i := int64(0); i < n; i++ {
v, err := rd.ReadReply(newGeoPositionParser())
if err != nil {
// response may contain nil results
if err == Nil {
positions = append(positions, nil)
continue
}
return nil, err
}
switch vv := v.(type) {
case *GeoPosition:
positions = append(positions, vv)
default:
return nil, fmt.Errorf("got %T, expected *GeoPosition", v)
}
}
return positions, nil
}
}
func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) {
var cmd CommandInfo
var err error