当前位置:网站首页>Redis learning notes - geographic information location (GEO)
Redis learning notes - geographic information location (GEO)
2022-06-23 09:11:00 【Love Guoba】
Redis3.2 Version provides GEO( Location of geographic information ) function , Support the storage of geographic location information to realize such as nearby location 、 Shake this kind of function that depends on Geographic Information , It is a great blessing for developers who need to implement these functions
Add location information
geoadd key longitude latitude member [longitude latitude member ...]
longitude、latitude、member They are the longitude of the geographical location 、 latitude 、 member
Add location information of Beijing
127.0.0.1:6379> geoadd cities 116.28 39.55 beijing
(integer) 1
If the addition is successful, return 1, Exists and will return 0, If you are modifying, you can also use geoadd, return 0
Add the location information of three cities Tianjin at the same time 、 Shanghai and Chongqing
127.0.0.1:6379> geoadd cities 117.12 39.08 tianjin 121.47 31.23 shanghai 106.55 29.57 chongqing
(integer) 3
Get geographic location information
geopos key member [member ...]
Get the location information of Shanghai , Get the location information of Shanghai and Chongqing at the same time
127.0.0.1:6379> geopos cities shanghai
1) 1) "121.47000163793563843"
2) "31.22999903975783553"
127.0.0.1:6379> geopos cities shanghai chongqing
1) 1) "121.47000163793563843"
2) "31.22999903975783553"
2) 1) "106.5499994158744812"
2) "29.5700000136221135"
Gets the distance between two geographical locations
geodist key member1 member2 [unit]
unit Representative unit , If it is not filled in, the default return company is m( rice ); You can enter the following four units
- m(meters) It's for rice
- km(kilometers) Representative kilometer
- mi(miles) For miles
- ft(feet) For ruler
Get the distance between Shanghai and Chongqing
127.0.0.1:6379> geodist cities shanghai chongqing
"1442064.7968"
127.0.0.1:6379> geodist cities shanghai chongqing km
"1442.0648"
Gets the collection of geographic information locations within the specified location range
georadius key longitude latitude radiusm|km|ft|mi [withcoord] [withdist] [withhash] [COUNT count] [asc|desc] [store key] [storedist key]
georadiusbymember key member radiusm|km|ft|mi [withcoord] [withdist] [withhash] [COUNT count] [asc|desc] [store key] [storedist key]
georadius and georadiusbymember The effect of the two commands is the same , All calculate other geographic information locations within the specified radius with one geographic location as the center , The difference is georadius The center position of the command gives the specific longitude and latitude ,georadiusbymember Just give the members . among radiusm|km|ft|mi Is the required parameter , The radius is specified ( With units ), These two commands have many optional parameters , As shown below
- withcoord: The return result contains latitude and longitude
- withdist: The return result contains the distance from the center node position
- withhash: The return result contains geohash, of geohash Later on
- COUNT count: Specify the number of returned results
- asc|desc: The returned results are in ascending or descending order according to the distance from the central node
- store key: Save the geographic location information of the returned result to the specified key
- storedist key: Save the distance between the returned result and the central node to the specified key
Get Beijing 1200km The cities within
127.0.0.1:6379> georadiusbymember cities beijing 1200 km
1) "beijing"
2) "tianjin"
3) "shanghai"
obtain geohash
geohash key member [member ...]
Redis Use geohash Convert two-dimensional latitude and longitude to one-dimensional string , The following operation will return beijing Of geohash value
127.0.0.1:6379> geohash cities beijing
1) "wx48ypbe2q0"
Delete geographic information
GEO There is no command to delete members , But because GEO The underlying implementation of zset, So you can borrow zrem Command to delete geographic location information
zrem key member
Delete location information of Beijing
127.0.0.1:6379> zrem cities beijing
(integer) 1
边栏推荐
猜你喜欢

"Coach, I want to play basketball" -- AI Learning Series booklet for students who are making systems

Redis学习笔记—客户端通讯协议RESP
Redis learning notes - data type: string (string)

297. Serialize and Deserialize Binary Tree

Learn SCI thesis drawing skills (E)

ionic5表单输入框和单选按钮

Custom tags - JSP tag enhancements

General paging (1)
Redis学习笔记—数据类型:字符串(string)

'coach, I want to play basketball!'—— AI Learning Series booklet for system students
随机推荐
S5P4418裸机编程的实现(替换2ndboot)
进入小公司的初级程序员要如何自我提高?
636. Exclusive Time of Functions
An idea of using keep alive to cache data in vue3 form pages
[advanced Android] kotlin notes
Redis学习笔记—redis-cli详解
位绑定
MySQL故障案例 | mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME
3、 System analysis and design
Redis learning notes - data type: ordered set (Zset)
Redis学习笔记—单个键管理
The sliding window of the force button "step by step" (209. sub array with the smallest length, 904. fruit basket)
Redis learning notes - data type: Set
一个采用直接映射方式的32KB缓存......存储器课后习题
自定义标签——jsp标签增强
Redis学习笔记—数据类型:集合(set)
Ionic5 form input box and radio button
Best time to buy and sell stock II
Happy number of leetcode topic analysis
How to use matrix analysis to build your thinking scaffold in flowus, notation and other note taking software