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:
42
parser.go
42
parser.go
@ -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
|
||||
|
Reference in New Issue
Block a user