@@ -178,195 +178,6 @@ export function transformLMPopArguments(
178
178
return args ;
179
179
}
180
180
181
- type GeoCountArgument = number | {
182
- value : number ;
183
- ANY ?: true
184
- } ;
185
-
186
- export function pushGeoCountArgument (
187
- args : CommandArguments ,
188
- count : GeoCountArgument | undefined
189
- ) : CommandArguments {
190
- if ( typeof count === 'number' ) {
191
- args . push ( 'COUNT' , count . toString ( ) ) ;
192
- } else if ( count ) {
193
- args . push ( 'COUNT' , count . value . toString ( ) ) ;
194
-
195
- if ( count . ANY ) {
196
- args . push ( 'ANY' ) ;
197
- }
198
- }
199
-
200
- return args ;
201
- }
202
-
203
- export type GeoUnits = 'm' | 'km' | 'mi' | 'ft' ;
204
-
205
- export interface GeoCoordinates {
206
- longitude : RedisArgument | number ;
207
- latitude : RedisArgument | number ;
208
- }
209
-
210
- type GeoSearchFromMember = string ;
211
-
212
- export type GeoSearchFrom = GeoSearchFromMember | GeoCoordinates ;
213
-
214
- interface GeoSearchByRadius {
215
- radius : number ;
216
- unit : GeoUnits ;
217
- }
218
-
219
- interface GeoSearchByBox {
220
- width : number ;
221
- height : number ;
222
- unit : GeoUnits ;
223
- }
224
-
225
- export type GeoSearchBy = GeoSearchByRadius | GeoSearchByBox ;
226
-
227
- export interface GeoSearchOptions {
228
- SORT ?: 'ASC' | 'DESC' ;
229
- COUNT ?: GeoCountArgument ;
230
- }
231
-
232
- export function pushGeoSearchArguments (
233
- args : CommandArguments ,
234
- key : RedisArgument ,
235
- from : GeoSearchFrom ,
236
- by : GeoSearchBy ,
237
- options ?: GeoSearchOptions
238
- ) : CommandArguments {
239
- args . push ( key ) ;
240
-
241
- if ( typeof from === 'string' ) {
242
- args . push ( 'FROMMEMBER' , from ) ;
243
- } else {
244
- args . push ( 'FROMLONLAT' , from . longitude . toString ( ) , from . latitude . toString ( ) ) ;
245
- }
246
-
247
- if ( 'radius' in by ) {
248
- args . push ( 'BYRADIUS' , by . radius . toString ( ) ) ;
249
- } else {
250
- args . push ( 'BYBOX' , by . width . toString ( ) , by . height . toString ( ) ) ;
251
- }
252
-
253
- args . push ( by . unit ) ;
254
-
255
- if ( options ?. SORT ) {
256
- args . push ( options . SORT ) ;
257
- }
258
-
259
- pushGeoCountArgument ( args , options ?. COUNT ) ;
260
-
261
- return args ;
262
- }
263
-
264
- export function pushGeoRadiusArguments (
265
- args : CommandArguments ,
266
- key : RedisArgument ,
267
- from : GeoSearchFrom ,
268
- radius : number ,
269
- unit : GeoUnits ,
270
- options ?: GeoSearchOptions
271
- ) : CommandArguments {
272
- args . push ( key ) ;
273
-
274
- if ( typeof from === 'string' ) {
275
- args . push ( from ) ;
276
- } else {
277
- args . push (
278
- from . longitude . toString ( ) ,
279
- from . latitude . toString ( )
280
- ) ;
281
- }
282
-
283
- args . push (
284
- radius . toString ( ) ,
285
- unit
286
- ) ;
287
-
288
- if ( options ?. SORT ) {
289
- args . push ( options . SORT ) ;
290
- }
291
-
292
- pushGeoCountArgument ( args , options ?. COUNT ) ;
293
-
294
- return args ;
295
- }
296
-
297
- export interface GeoRadiusStoreOptions extends GeoSearchOptions {
298
- STOREDIST ?: boolean ;
299
- }
300
-
301
- export function pushGeoRadiusStoreArguments (
302
- args : CommandArguments ,
303
- key : RedisArgument ,
304
- from : GeoSearchFrom ,
305
- radius : number ,
306
- unit : GeoUnits ,
307
- destination : RedisArgument ,
308
- options ?: GeoRadiusStoreOptions
309
- ) : CommandArguments {
310
- pushGeoRadiusArguments ( args , key , from , radius , unit , options ) ;
311
-
312
- if ( options ?. STOREDIST ) {
313
- args . push ( 'STOREDIST' , destination ) ;
314
- } else {
315
- args . push ( 'STORE' , destination ) ;
316
- }
317
-
318
- return args ;
319
- }
320
-
321
- export enum GeoReplyWith {
322
- DISTANCE = 'WITHDIST' ,
323
- HASH = 'WITHHASH' ,
324
- COORDINATES = 'WITHCOORD'
325
- }
326
-
327
- export interface GeoReplyWithMember {
328
- member : string ;
329
- distance ?: number ;
330
- hash ?: string ;
331
- coordinates ?: {
332
- longitude : string ;
333
- latitude : string ;
334
- } ;
335
- }
336
-
337
- export function transformGeoMembersWithReply ( reply : Array < Array < any > > , replyWith : Array < GeoReplyWith > ) : Array < GeoReplyWithMember > {
338
- const replyWithSet = new Set ( replyWith ) ;
339
-
340
- let index = 0 ;
341
- const distanceIndex = replyWithSet . has ( GeoReplyWith . DISTANCE ) && ++ index ,
342
- hashIndex = replyWithSet . has ( GeoReplyWith . HASH ) && ++ index ,
343
- coordinatesIndex = replyWithSet . has ( GeoReplyWith . COORDINATES ) && ++ index ;
344
-
345
- return reply . map ( member => {
346
- const transformedMember : GeoReplyWithMember = {
347
- member : member [ 0 ]
348
- } ;
349
-
350
- if ( distanceIndex ) {
351
- transformedMember . distance = member [ distanceIndex ] ;
352
- }
353
-
354
- if ( hashIndex ) {
355
- transformedMember . hash = member [ hashIndex ] ;
356
- }
357
-
358
- if ( coordinatesIndex ) {
359
- const [ longitude , latitude ] = member [ coordinatesIndex ] ;
360
- transformedMember . coordinates = {
361
- longitude,
362
- latitude
363
- } ;
364
- }
365
-
366
- return transformedMember ;
367
- } ) ;
368
- }
369
-
370
181
export function transformEXAT ( EXAT : number | Date ) : string {
371
182
return ( typeof EXAT === 'number' ? EXAT : Math . floor ( EXAT . getTime ( ) / 1000 ) ) . toString ( ) ;
372
183
}
0 commit comments