-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_geospatial.go
262 lines (239 loc) · 12.1 KB
/
cmd_geospatial.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package redisson
import (
"context"
)
type GeospatialCmdable interface {
GeospatialWriter
}
type GeospatialWriter interface {
// GeoAdd
// Available since: 3.2.0
// Time complexity: O(log(N)) for each item added, where N is the number of elements in the sorted set.
// ACL categories: @write @geo @slow
// Options
// - XX: Only update elements that already exist. Never add elements.
// - NX: Don't update already existing elements. Always add new elements.
// - CH: Modify the return value from the number of new elements added, to the total number of elements changed (CH is an abbreviation of changed).
// Changed elements are new elements added and elements already existing for which the coordinates was updated. So elements specified in the
// command line having the same score as they had in the past are not counted. Note: normally, the return value of GEOADD only counts the number of new elements added.
// Note: The XX and NX options are mutually exclusive.
// RESP2 / RESP3 Reply:
// - Integer reply: When used without optional arguments, the number of elements added to the sorted set (excluding score updates).
// If the CH option is specified, the number of elements that were changed (added or updated).
// History:
// - Starting with Redis version 6.2.0: Added the CH, NX and XX options.
GeoAdd(ctx context.Context, key string, geoLocation ...GeoLocation) IntCmd
// GeoRadiusStore
// Available since: 3.2.0
// Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.
// ACL categories: @write @geo @slow
// RESP2 / RESP3 Reply:
// One of the following:
// - If no WITH* option is specified, an Array reply of matched member names
// - If WITHCOORD, WITHDIST, or WITHHASH options are specified, the command returns an Array reply of arrays, where each sub-array represents a single item:
// 1. The distance from the center as a floating point number, in the same unit specified in the radius.
// 2. The Geohash integer.
// 3. The coordinates as a two items x,y array (longitude,latitude).
// History:
// - Starting with Redis version 6.2.0: Added the ANY option for COUNT.
// - Starting with Redis version 7.0.0: Added support for uppercase unit names.
GeoRadiusStore(ctx context.Context, key string, longitude, latitude float64, query GeoRadiusQuery) IntCmd
// GeoRadiusByMemberStore
// Available since: 3.2.0
// Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.
// ACL categories: @write @geo @slow
// RESP2 / RESP3 Reply:
// One of the following:
// - If no WITH* option is specified, an Array reply of matched member names
// - If WITHCOORD, WITHDIST, or WITHHASH options are specified, the command returns an Array reply of arrays, where each sub-array represents a single item:
// 1. The distance from the center as a floating point number, in the same unit specified in the radius.
// 2. The Geohash integer.
// 3. The coordinates as a two items x,y array (longitude,latitude).
// History:
// - Starting with Redis version 7.0.0: Added support for uppercase unit names.
GeoRadiusByMemberStore(ctx context.Context, key, member string, query GeoRadiusQuery) IntCmd
// GeoSearchStore
// Available since: 6.2.0
// Time complexity: O(N+log(M)) where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter and M is the number of items inside the shape
// ACL categories: @write @geo @slow
// RESP2 / RESP3 Reply:
// - Integer reply: the number of elements in the resulting set
// History:
// - Starting with Redis version 7.0.0: Added support for uppercase unit names.
GeoSearchStore(ctx context.Context, key, store string, q GeoSearchStoreQuery) IntCmd
}
type GeospatialCacheCmdable interface {
// GeoDist
// Available since: 3.2.0
// Time complexity: O(1)
// ACL categories: @read @geo @slow
// Options
// - M for meters.
// - KM for kilometers.
// - MI for miles.
// - FT for feet.
// RESP2 Reply:
// One of the following:
// - Nil reply: one or both of the elements are missing.
// - Bulk string reply: distance as a double (represented as a string) in the specified units.
// RESP3 Reply:
// One of the following:
// - Null reply: one or both of the elements are missing.
// - Bulk string reply: distance as a double (represented as a string) in the specified units.
GeoDist(ctx context.Context, key string, member1, member2, unit string) FloatCmd
// GeoHash
// Available since: 3.2.0
// Time complexity: O(1) for each member requested.
// ACL categories: @read @geo @slow
// RESP2 / RESP3 Reply:
// - Array reply: an array where each element is the Geohash corresponding to each member name passed as an argument to the command.
GeoHash(ctx context.Context, key string, members ...string) StringSliceCmd
// GeoPos
// Available since: 3.2.0
// Time complexity: O(1) for each member requested.
// ACL categories: @read @geo @slow
// RESP2 Reply:
// - Array reply: An array where each element is a two elements array representing longitude and latitude (x,y) of
// each member name passed as argument to the command. Non-existing elements are reported as Nil reply elements of the array.
// RESP3 Reply:
// - Array reply: An array where each element is a two elements array representing longitude and latitude (x,y) of
// each member name passed as argument to the command. Non-existing elements are reported as Null reply elements of the array.
GeoPos(ctx context.Context, key string, members ...string) GeoPosCmd
// GeoRadius
// Available since: 3.2.10
// Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.
// ACL categories: @read @geo @slow
// RESP2 / RESP3 Reply:
// One of the following:
// - If no WITH* option is specified, an Array reply of matched member names
// - If WITHCOORD, WITHDIST, or WITHHASH options are specified, the command returns an Array reply of arrays, where each sub-array represents a single item:
// 1. The distance from the center as a floating point number, in the same unit specified in the radius.
// 2. The Geohash integer.
// 3. The coordinates as a two items x,y array (longitude,latitude).
// History:
// - Starting with Redis version 6.2.0: Added the ANY option for COUNT.
GeoRadius(ctx context.Context, key string, longitude, latitude float64, query GeoRadiusQuery) GeoLocationCmd
// GeoRadiusByMember
// Available since: 3.2.10
// Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.
// ACL categories: @read @geo @slow
// RESP2 / RESP3 Reply:
// One of the following:
// - If no WITH* option is specified, an Array reply of matched member names
// - If WITHCOORD, WITHDIST, or WITHHASH options are specified, the command returns an Array reply of arrays, where each sub-array represents a single item:
// 1. The distance from the center as a floating point number, in the same unit specified in the radius.
// 2. The Geohash integer.
// 3. The coordinates as a two items x,y array (longitude,latitude).
GeoRadiusByMember(ctx context.Context, key, member string, query GeoRadiusQuery) GeoLocationCmd
// GeoSearch
// Available since: 6.2.0
// Time complexity: O(N+log(M)) where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter and M is the number of items inside the shape
// ACL categories: @read @geo @slow
// RESP2 / RESP3 Reply:
// One of the following:
// - If no WITH* option is specified, an Array reply of matched member names
// - If WITHCOORD, WITHDIST, or WITHHASH options are specified, the command returns an Array reply of arrays, where each sub-array represents a single item:
// 1. The distance from the center as a floating point number, in the same unit specified in the radius.
// 2. The Geohash integer.
// 3. The coordinates as a two items x,y array (longitude,latitude).
// History:
// - Starting with Redis version 7.0.0: Added support for uppercase unit names.
GeoSearch(ctx context.Context, key string, q GeoSearchQuery) StringSliceCmd
GeoSearchLocation(ctx context.Context, key string, q GeoSearchLocationQuery) GeoLocationCmd
}
func (c *client) GeoAdd(ctx context.Context, key string, geoLocation ...GeoLocation) IntCmd {
ctx = c.handler.before(ctx, CommandGeoAdd)
r := c.adapter.GeoAdd(ctx, key, geoLocation...)
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoDist(ctx context.Context, key string, member1, member2, unit string) FloatCmd {
ctx = c.handler.before(ctx, CommandGeoDist)
var r FloatCmd
if c.ttl > 0 {
r = newFloatCmd(c.Do(ctx, c.builder.GeoDistCompleted(key, member1, member2, unit)))
} else {
r = c.adapter.GeoDist(ctx, key, member1, member2, unit)
}
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoHash(ctx context.Context, key string, members ...string) StringSliceCmd {
ctx = c.handler.before(ctx, CommandGeoHash)
r := newStringSliceCmd(c.Do(ctx, c.builder.GeoHashCompleted(key, members...)))
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoPos(ctx context.Context, key string, members ...string) GeoPosCmd {
ctx = c.handler.before(ctx, CommandGeoPos)
var r GeoPosCmd
if c.ttl > 0 {
r = newGeoPosCmd(c.Do(ctx, c.builder.GeoPosCompleted(key, members...)))
} else {
r = c.adapter.GeoPos(ctx, key, members...)
}
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoRadius(ctx context.Context, key string, longitude, latitude float64, query GeoRadiusQuery) GeoLocationCmd {
ctx = c.handler.before(ctx, CommandGeoRadiusRO)
var r GeoLocationCmd
if c.ttl > 0 {
r = newGeoLocationCmd(c.Do(ctx, c.builder.GeoRadiusCompleted(key, longitude, latitude, query)))
} else {
r = c.adapter.GeoRadius(ctx, key, longitude, latitude, query)
}
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoRadiusStore(ctx context.Context, key string, longitude, latitude float64, query GeoRadiusQuery) IntCmd {
f := func() []string {
if len(query.Store) > 0 && len(query.StoreDist) > 0 {
return appendString(key, query.Store, query.StoreDist)
} else if len(query.Store) > 0 {
return appendString(key, query.Store)
} else if len(query.StoreDist) > 0 {
return appendString(key, query.StoreDist)
}
return nil
}
ctx = c.handler.beforeWithKeys(ctx, CommandGeoRadiusStore, f)
r := c.adapter.GeoRadiusStore(ctx, key, longitude, latitude, query)
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoRadiusByMember(ctx context.Context, key, member string, query GeoRadiusQuery) GeoLocationCmd {
ctx = c.handler.before(ctx, CommandGeoRadiusByMemberRO)
var r GeoLocationCmd
if c.ttl > 0 {
r = newGeoLocationCmd(c.Do(ctx, c.builder.GeoRadiusByMemberCompleted(key, member, query)))
} else {
r = c.adapter.GeoRadiusByMember(ctx, key, member, query)
}
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoRadiusByMemberStore(ctx context.Context, key, member string, query GeoRadiusQuery) IntCmd {
ctx = c.handler.before(ctx, CommandGeoRadiusByMemberStore)
r := c.adapter.GeoRadiusByMemberStore(ctx, key, member, query)
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoSearch(ctx context.Context, key string, q GeoSearchQuery) StringSliceCmd {
ctx = c.handler.before(ctx, CommandGeoSearch)
r := newStringSliceCmd(c.Do(ctx, c.builder.GeoSearchCompleted(key, q)))
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoSearchLocation(ctx context.Context, key string, q GeoSearchLocationQuery) GeoLocationCmd {
ctx = c.handler.before(ctx, CommandGeoSearchLocation)
r := c.adapter.GeoSearchLocation(ctx, key, q)
c.handler.after(ctx, r.Err())
return r
}
func (c *client) GeoSearchStore(ctx context.Context, key, store string, q GeoSearchStoreQuery) IntCmd {
ctx = c.handler.before(ctx, CommandGeoSearchStore)
r := c.adapter.GeoSearchStore(ctx, key, store, q)
c.handler.after(ctx, r.Err())
return r
}