Mainly because Redis uses ordered sets to store location objects, which can be deleted by zrem. Redis geo operations only include "add" and "check" operations, and there is no special "delete" command. The following will analyze GEOADD and GEORADIUS commands from the source code point of view, and analyze their algorithm principles. However, essentially, GEORADIUSBYMEMBER = GEOPOS + GEORADIUS, that is to say, first find the user's location and then search for other user objects that satisfy the condition of location distance. The "given location object" is the user himself, and the search object is other users. In order to realize the function of "people nearby" in micro-letters, the GEORADIUSBYMEMBER command can be used directly. GEORADIUSBYMEMBER: Returns all location objects whose distances do not exceed the maximum given distance as the center of a given location object.Īmong them, the combination of GEOADD and GEORADIUS can realize the basic functions of "adding" and "checking" in "nearby people". GEORADIUS: Regarding the given longitude and latitude as the center, returns all the location objects whose distance from the center in the target set does not exceed the given maximum distance. GEOHASH: A Geohash representation that returns one or more location objects GEODIST: Returns the distance between two given locations GEOPOS: Returns the location (longitude and latitude) of all given location objects from key. GEOADD: Adds a given location object (latitude, longitude, name) to the specified key The Redis Geo module contains the following six commands: Since Redis 3.2, Redis has provided geolocation-related functions based on geohash and ordered sets. The following will be introduced separately, which will focus on the analysis of query function. To provide a complete "nearby people" service, the most basic thing is to realize the functions of "adding", "deleting" and "checking". This paper will analyze the algorithm principle from the source code point of view, and calculate the query time complexity. Redis, which combines its ordered queue zset and geohash coding, achieves the function of spatial search and has a very high operational efficiency. For the application scenario of "nearby people" in the field of location-based services, many spatial indexes such as PG, MySQL and Mongo DB can be used to implement it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |