1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Added binding for GEOADD and GEORADIUS.

This commit is contained in:
Ian Chan
2015-09-20 14:13:13 +01:00
committed by Vladimir Mihailenco
parent eef3fd78ef
commit 8a05670e7a
3 changed files with 231 additions and 0 deletions

View File

@ -1671,3 +1671,75 @@ func (c *commandable) ClusterAddSlotsRange(min, max int) *StatusCmd {
}
return c.ClusterAddSlots(slots...)
}
//------------------------------------------------------------------------------
func (c *commandable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd {
args := make([]interface{}, 2+3*len(geoLocation))
args[0] = "GEOADD"
args[1] = key
for i, eachLoc := range geoLocation {
args[2+3*i] = eachLoc.Longitude
args[2+3*i+1] = eachLoc.Latitude
args[2+3*i+2] = eachLoc.Name
}
cmd := NewIntCmd(args...)
c.Process(cmd)
return cmd
}
func (c *commandable) GeoRadius(query *GeoRadiusQuery) *GeoCmd {
var options, optionsCtr int
if query.WithCoordinates {
options++
}
if query.WithDistance {
options++
}
if query.WithGeoHash {
options++
}
if query.Count > 0 {
options += 2
}
if query.Sort != "" {
options++
}
args := make([]interface{}, 6 + options)
args[0] = "GEORADIUS"
args[1] = query.Key
args[2] = query.Longitude
args[3] = query.Latitude
args[4] = query.Radius
if query.Unit != "" {
args[5] = query.Unit
} else {
args[5] = "km"
}
if query.WithCoordinates {
args[6+optionsCtr] = "WITHCOORD"
optionsCtr++
}
if query.WithDistance {
args[6+optionsCtr] = "WITHDIST"
optionsCtr++
}
if query.WithGeoHash {
args[6+optionsCtr] = "WITHHASH"
optionsCtr++
}
if query.Count > 0 {
args[6+optionsCtr] = "COUNT"
optionsCtr++
args[6+optionsCtr] = query.Count
optionsCtr++
}
if query.Sort != "" {
args[6+optionsCtr] = query.Sort
}
cmd := NewGeoCmd(args...)
c.Process(cmd)
return cmd
}