Merge pull request #600 from go-redis/fix/geo-ro-variants

Add Geo commands read-only variants
This commit is contained in:
Vladimir Mihailenco 2017-07-19 15:40:17 +03:00 committed by GitHub
commit 8ca3198da9
2 changed files with 29 additions and 5 deletions

View File

@ -800,6 +800,8 @@ type GeoRadiusQuery struct {
Count int Count int
// Can be ASC or DESC. Default is no sort order. // Can be ASC or DESC. Default is no sort order.
Sort string Sort string
Store string
StoreDist string
} }
type GeoLocationCmd struct { type GeoLocationCmd struct {
@ -817,20 +819,28 @@ func NewGeoLocationCmd(q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd {
args = append(args, "km") args = append(args, "km")
} }
if q.WithCoord { if q.WithCoord {
args = append(args, "WITHCOORD") args = append(args, "withcoord")
} }
if q.WithDist { if q.WithDist {
args = append(args, "WITHDIST") args = append(args, "withdist")
} }
if q.WithGeoHash { if q.WithGeoHash {
args = append(args, "WITHHASH") args = append(args, "withhash")
} }
if q.Count > 0 { if q.Count > 0 {
args = append(args, "COUNT", q.Count) args = append(args, "count", q.Count)
} }
if q.Sort != "" { if q.Sort != "" {
args = append(args, q.Sort) args = append(args, q.Sort)
} }
if q.Store != "" {
args = append(args, "store")
args = append(args, q.Store)
}
if q.StoreDist != "" {
args = append(args, "storedist")
args = append(args, q.StoreDist)
}
return &GeoLocationCmd{ return &GeoLocationCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{_args: args},
q: q, q: q,

View File

@ -234,7 +234,9 @@ type Cmdable interface {
GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd
GeoPos(key string, members ...string) *GeoPosCmd GeoPos(key string, members ...string) *GeoPosCmd
GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd
GeoRadiusRO(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd
GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
GeoDist(key string, member1, member2, unit string) *FloatCmd GeoDist(key string, member1, member2, unit string) *FloatCmd
GeoHash(key string, members ...string) *StringSliceCmd GeoHash(key string, members ...string) *StringSliceCmd
Command() *CommandsInfoCmd Command() *CommandsInfoCmd
@ -2061,12 +2063,24 @@ func (c *cmdable) GeoRadius(key string, longitude, latitude float64, query *GeoR
return cmd return cmd
} }
func (c *cmdable) GeoRadiusRO(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
cmd := NewGeoLocationCmd(query, "georadius_ro", key, longitude, latitude)
c.process(cmd)
return cmd
}
func (c *cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd { func (c *cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
cmd := NewGeoLocationCmd(query, "georadiusbymember", key, member) cmd := NewGeoLocationCmd(query, "georadiusbymember", key, member)
c.process(cmd) c.process(cmd)
return cmd return cmd
} }
func (c *cmdable) GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
cmd := NewGeoLocationCmd(query, "georadiusbymember_ro", key, member)
c.process(cmd)
return cmd
}
func (c *cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd { func (c *cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd {
if unit == "" { if unit == "" {
unit = "km" unit = "km"