当前位置:网站首页>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
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 …]
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 …]
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]
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]
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]
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 …]
边栏推荐
- ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
- Mongodb installation and basic operation
- [OC-Foundation框架]--<Copy对象复制>
- I-BERT
- Pytest参数化你不知道的一些使用技巧 /你不知道的pytest
- 【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
- Intel distiller Toolkit - Quantitative implementation 1
- MySQL uninstallation and installation methods
- [OC-Foundation框架]---【集合数组】
- 在QWidget上实现窗口阻塞
猜你喜欢
[oc]- < getting started with UI> -- learning common controls
如何正确截取字符串(例:应用报错信息截取入库操作)
Intel distiller Toolkit - Quantitative implementation 3
数字人主播618手语带货,便捷2780万名听障人士
BMINF的後訓練量化實現
opencv+dlib实现给蒙娜丽莎“配”眼镜
Compétences en mémoire des graphiques UML
一篇文章带你了解-selenium工作原理详解
Different data-driven code executes the same test scenario
Multivariate cluster analysis
随机推荐
AcWing 2456. Notepad
How to intercept the string correctly (for example, intercepting the stock in operation by applying the error information)
requests的深入刨析及封装调用
Intel Distiller工具包-量化实现3
如何正确截取字符串(例:应用报错信息截取入库操作)
Seven layer network architecture
LeetCode:498. Diagonal traversal
Nacos installation and service registration
[oc foundation framework] - < copy object copy >
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
BMINF的後訓練量化實現
LeetCode:387. The first unique character in the string
Advanced Computer Network Review(4)——Congestion Control of MPTCP
UML图记忆技巧
KDD 2022 paper collection (under continuous update)
Advanced Computer Network Review(3)——BBR
go-redis之初始化连接
Mongodb installation and basic operation
LeetCode41——First Missing Positive——hashing in place & swap
Leetcode: Sword finger offer 48 The longest substring without repeated characters