当前位置:网站首页>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 …]
边栏推荐
- [OC-Foundation框架]--<Copy对象复制>
- I-BERT
- 不同的数据驱动代码执行相同的测试场景
- [today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
- Selenium+pytest automated test framework practice
- Redis之cluster集群
- Export IEEE document format using latex
- Improved deep embedded clustering with local structure preservation (Idec)
- Advanced Computer Network Review(3)——BBR
- Five layer network architecture
猜你喜欢
自定义卷积注意力算子的CUDA实现
Selenium+Pytest自动化测试框架实战(下)
[sword finger offer] serialized binary tree
The carousel component of ant design calls prev and next methods in TS (typescript) environment
Intel Distiller工具包-量化实现1
Kratos战神微服务框架(二)
多元聚类分析
LeetCode41——First Missing Positive——hashing in place & swap
BN折叠及其量化
Mongodb installation and basic operation
随机推荐
[three storage methods of graph] just use adjacency matrix to go out
UML圖記憶技巧
Selenium+Pytest自动化测试框架实战
Intel Distiller工具包-量化实现3
LeetCode:39. Combined sum
[OC-Foundation框架]--<Copy对象复制>
Redis之主从复制
甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
Pytest参数化你不知道的一些使用技巧 /你不知道的pytest
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
Leetcode: Jianzhi offer 04 Search in two-dimensional array
在QWidget上实现窗口阻塞
[Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
QDialog
Multivariate cluster analysis
Redis之核心配置
Simclr: comparative learning in NLP
BMINF的後訓練量化實現
Using label template to solve the problem of malicious input by users