当前位置:网站首页>Redis geospatial
Redis geospatial
2022-07-06 09:14:00 【~Pompeii】
Catalog
Redis And Geospatial
1.Geospatial Introduce
Redis stay 3.2 Geospatial has been added to the version (geospatial) And the function of index radius query , It is mainly used in applications that need geographical location . Geospatial location to be specified ( longitude 、 latitude 、 name ) Add to specified key in , This data will be stored in sorted set. The purpose is to facilitate the use of GEORADIUS perhaps GEORADIUSBYMEMBER Command to query the radius of data . in other words , Calculate the information of geographical location , The distance between the two places , People around you and other scenes can be realized with it .
Summary :geo The underlying principle is to use zset To achieve
2.Geospatial Basic operation
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-tb3ynZZw-1656813849252)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220702171605667.png)]](/img/6b/77df68e20112c99f3820b1b4d67a84.png)
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-xVtAUG1H-1656813849254)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220702172958411.png)]](/img/9c/4d69a7f0e3088662397bae638b885d.png)
3.Geospatial Application scenarios
Applied to geographic location calculation
4.geoadd command
Time complexity : The complexity of each added element is O(log(N)) , among N Is the number of position elements contained in the key .
Return value : Number of space elements newly added to the key , Does not include elements that already exist but have been updated ;
When the user tries to enter an out of range longitude or latitude , GEOADD The command will return an error .
Will give the space element ( latitude 、 longitude 、 name ) Add to the specified key . The data will be stored in keys in an ordered set , To make it look like GEORADIUS and GEORADIUSBYMEMBER Such a command can later retrieve these elements through a location query .
GEOADD Order by standard x,y Format accepts parameters , So the user has to enter longitude first , And then input latitude . GEOADD The coordinates that can be recorded are limited : Areas very close to the poles cannot be indexed . The precise coordinates are limited by EPSG:900913 / EPSG:3785 / OSGEO:41001 Coordinate system definition , As follows :
1) The effective longitude is between -180 Degree to 180 Between degrees .
2) The effective latitude is between -85.05112878 Degree to 85.05112878 Between degrees .
GEOADD key longitude latitude member [longitude latitude member …]
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-R9yMdewi-1656813849254)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220702173726344.png)]](/img/bd/708aa1485f83b984d8f1951d681b34.png)
5.geopos command
Time complexity : The complexity of getting each location element is O(log(N)) , among N Is the number of position elements contained in the key .
Return value :
GEOPOS Command returns an array , Each item in the array consists of two elements : The first element is the longitude of the positioning element , The second element is the latitude of the location element . When the given location element does not exist , The corresponding array item is null .
Return all the positions of the positioning elements from the key ( Longitude and latitude ).
because GEOPOS The command accepts a variable number of positional elements as input , So even if the user only gives a location element , The command also returns an array reply .
GEOPOS key member [member …]
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-LPnlTWvl-1656813849255)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220703095247938.png)]](/img/4c/d22a72dc21dc1916b4cc7da1880627.png)
6.geodist command
Time complexity :O(log(N))
Return value :
The calculated distance is returned as a double precision floating-point number . If the given location element does not exist , Then the command returns a null value .
Returns the distance between two given positions .
If one of the two positions does not exist , Then the command returns a null value .
Parameters for specified units unit Must be one of the following units :
1)m Expressed in meters .
2)km Expressed in kilometers .
3)mi In miles .
4)ft In feet .
If the user does not explicitly specify the unit parameter , that GEODIST The default is meters .
GEODIST The command assumes that the earth is perfectly spherical when calculating distance , In extreme cases , This assumption will lead to 0.5% The error of the .
GEODIST key member1 member2 [unit]
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-gbOhpAHz-1656813849255)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220703095533265.png)]](/img/43/8fabcf0ca2fcc17ff488e9d562dba5.png)
7.georadius command
Time complexity : O(N+log(M)), among N Is the number of position elements within the specified radius , and M Is the number of returned location elements .
Return value :
GEORADIUS Command returns an array , say concretely :
1. In the absence of any given WITH In the case of options , The command will only return an image like [“New York”,“Milan”,“Paris”] Such linearity (linear) list .
2. In the specified WITHCOORD 、 WITHDIST 、 WITHHASH Wait for options , The command returns a two-level nested array , Each subarray of the inner layer represents an element .
When returning nested arrays , The first element of a subarray is always the name of the positional element . As for additional information , It will be used as a subsequent element of the subarray , Is returned in the following order :
1) The distance between the center and the location element returned in floating-point format , The unit is the same as that specified by the user .
2)geohash Integers .
3) A coordinate consisting of two elements , They are longitude and latitude .
for instance , GEORADIUS Sicily 15 37 200 km withcoord withdist Each subarray returned by such a command is similar to the following format :
[“Palermo”,“190.4424”,[“13.361389338970184”,“38.115556395496299”]]
Centered on a given latitude and longitude , Return key contains position elements , All position elements whose distance from the center does not exceed the given maximum distance .
Range can use one of the following units :
1)m Expressed in meters .
2)km Expressed in kilometers .
3)mi In miles .
4)ft In feet .
When the following options are given , The command will return additional information :
1)WITHDIST : While returning location elements , Return the distance between the location element and the center as well . The unit of distance is consistent with the unit of range given by the user .
2)WITHCOORD : Return the longitude and dimension of the location element as well .
3)WITHHASH : With 52 Bit signed integer form , Return the location element through the original geohash Encoded ordered set score . This option is mainly used for underlying applications or debugging , It doesn't really work .
The command returns unordered location elements by default . Through the following two parameters , The user can specify the sorting method of the returned location elements :
1)ASC : According to the position of the center , Return the location element in a near to far way .
2)DESC : According to the position of the center , Return the location elements from far to near .
By default , GEORADIUS The command returns all matching location elements . Although users can use COUNT Options to get before N Match elements , But because the command may need to handle all the matched elements internally , So when you search for a very large area , Even if you only use COUNT Option to get a few elements , Command execution can also be very slow . But on the other hand , Use COUNT Option to reduce the number of elements to be returned , It's still very useful for reducing bandwidth .
GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [ASC|DESC] [COUNT count]
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-EKHIT3Tw-1656813849256)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220703100056046.png)]](/img/c9/7cda5eb4174ca57347c0ae631a8fb0.png)
8.georadiusbymember command
Time complexity : O(log(N)+M), among N For the number of elements in the specified range , and M Is the number of elements returned .
Return value :
An array , Each item in the array represents a range of location elements .
This command and GEORADIUS command , Can find the elements in the specified range , however georadiusbymember The center point of is determined by a given location element , Not like it GEORADIUS like that , Use the entered longitude and latitude to determine the center point .
GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [ASC|DESC] [COUNT count]
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-qaBsLTIm-1656813849256)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220703100203337.png)]](/img/71/ee50e336eefbab8c7a185766beec68.png)
9.geohash command
Time complexity : The complexity of finding each location element is O(log(N)) , among N The number of positional elements contained for a given key
Returns the... Of one or more positional elements Geohash Express
Return value :
An array , Each item in the array is a geohash . Command returned geohash The location of the element corresponds to the location given by the user one by one .
GEOHASH key member [member …]
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-GaTc9fr6-1656813849257)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220703100314943.png)]](/img/21/83d89192ab4965cd728c271b2ac145.png)
边栏推荐
- Leetcode: Jianzhi offer 03 Duplicate numbers in array
- I-BERT
- Advance Computer Network Review(1)——FatTree
- [sword finger offer] serialized binary tree
- CUDA implementation of self defined convolution attention operator
- 注意力机制的一种卷积替代方式
- Reids之缓存预热、雪崩、穿透
- [OC-Foundation框架]-<字符串And日期与时间>
- LeetCode:162. Looking for peak
- I-BERT
猜你喜欢
![[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born](/img/70/d275009134fcbf9ae984c0f278659e.jpg)
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born

Redis之cluster集群

Intel Distiller工具包-量化实现2
![[OC foundation framework] - string and date and time >](/img/75/e20064fd0066810135771a01f54360.png)
[OC foundation framework] - string and date and time >

Nacos installation and service registration

Problems encountered in connecting the database of the project and their solutions

Redis之Bitmap

Using C language to complete a simple calculator (function pointer array and callback function)

Redis cluster

Intel distiller Toolkit - Quantitative implementation 3
随机推荐
CSP salary calculation
Show slave status \ read in G_ Master_ Log_ POS and relay_ Log_ The (size) relationship of POS
MySQL uninstallation and installation methods
LeetCode:673. Number of longest increasing subsequences
Intel Distiller工具包-量化实现1
Philosophical enlightenment from single point to distributed
Five layer network architecture
Le modèle sentinelle de redis
Pytest之收集用例规则与运行指定用例
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
Detailed explanation of dynamic planning
Pytest parameterization some tips you don't know / pytest you don't know
Reids之删除策略
Advance Computer Network Review(1)——FatTree
一篇文章带你了解-selenium工作原理详解
Redis之哨兵模式
Li Kou daily question 1 (2)
Advanced Computer Network Review(5)——COPE
Once you change the test steps, write all the code. Why not try yaml to realize data-driven?
[oc]- < getting started with UI> -- common controls uibutton