Redis GEO Location

Redis 3.2 version of the new GEO (location).

GEO instructions

GEOADD

命令:GEOADD key longitude latitude member [longitude latitude member ...]

Command Description: The specified geospatial position (latitude, longitude, name) added to the specified keymedium.

Returns: The number added to the sorted set of elements, but does not include elements of the updated score.

Time complexity: O (log (N))

GEODIST

命令:GEODIST key member1 member2 [unit]

Command Description:

Returns the distance between the two given positions. If a location between the two does not exist, then the command returns a null value. Parameter specifies the units of unit must be one of the following units:

  • m m
  • km one thousand meters
  • mi mi
  • ft ft

Time complexity: O (log (N))

GEOPOP

命令:GEOPOS key member [member ...]

Command Description: Returns all element positions given position (latitude and longitude) in the key.

Return Value: GEOPOS command returns an array, each entry in the array consists of two elements: a first element for the given position of the element of longitude, and the second element position of the element was given latitude. When a given position element does not exist, the corresponding array entry to the null value.

Time complexity: O (log (N))

GEOHASH

命令:GEOHASH key member [member ...]

Command Description: Returns the position of one or more elements Geohash FIG. Usually it indicates the position of the elements using different techniques, using integer coding Geohash position 52 points. Since different initial minimum and maximum coordinates in the encoding and decoding processes used in coding is also different coding standards. This command returns a standard Geohash

Returns: an array, each item is a geohash array. Geohash position command returns the position of the user with the given position of the elements correspond.

Time complexity: O (log (N))

GEORADIUS

命令:GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count]

Command Description:

A given latitude and longitude as the center, from the position of the element which contains the return key, the center positions of all the elements does not exceed a given maximum distance. WITHDIST return distance can be specified, WITHCOORD returned latitude and longitude, WITHHASH geohash return value. You can specify ASC or DESC, sorted according to the distance. You can specify the number of records returned COUNT defined.

Time complexity: O (N + log (M)), N is the number of elements within a specified radius, M being the number to be returned.

GEORADIUSBYMEMBER

命令:GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count]

Command Description: This command and GEORADIUS commands, can identify elements located within the specified range, but the central point GEORADIUSBYMEMBER is determined by the position of a given element. WITHDIST return distance can be specified, WITHCOORD returned latitude and longitude, WITHHASH geohash return value. You can specify ASC or DESC, sorted according to the distance. You can specify the number of records returned COUNT defined.

Time complexity: O (log (N) + M), N is the number of elements within a specified radius, M being the number to be returned.

Supplementary instructions

Deletion

Redis GEO operation only by check, do not delete the command, because it is using zset save the object, you can use zrem deleted.

Avoid excessive number of single collection

By providing a plurality of single key set avoid excessive quantity.

Storage principle

GEOADD storage principle

Internal storage zset ordered set, score value of an element corresponding to latitude and longitude values ​​geohash 52, geohash manner base32 encoding.

  1. Parameter extraction and calibration.
  2. 52 converts the latitude and longitude values ​​as geohash score.
  3. Call zadd instructions stored member and score.

GEOHASH accuracy problems

 Latitude的范围是:-90 到 +90
 Longitude的范围:-180 到 +180
 地球参考球体的周长:40075016.68米

Guess you like

Origin www.cnblogs.com/ylty/p/11921006.html
GEO