当前位置:网站首页>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
边栏推荐
- Redis学习笔记—redis-cli详解
- Unity grid programming 06
- 栈(Stack)的链式实现详解----线性结构
- Map接口的注意事项
- Custom tag - JSP tag Foundation
- 36氪首发|云原生数据库公司「拓数派」完成新一轮战略融资,估值已达准独角兽级别
- Lua的基本使用
- Kotlin Series 1: getting started with basics
- MySQL故障案例 | mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME
- How thingjs enables low threshold 3D visualization development
猜你喜欢
Redis学习笔记—发布订阅

“教练,我想打篮球“ —— 给做系统的同学们准备的 AI 学习系列小册

自定义标签——jsp标签基础
![[learning resources] understand and love mathematics](/img/a3/e1b0915c48c85d17c48a4bee523424.png)
[learning resources] understand and love mathematics

扫码登录基本流程
![[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24](/img/e1/97c92290a2a5e68f05cdbd5bf525e8.png)
[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24

通用分页(1)

Map接口的注意事项

Servlet-02 生命周期

Basic process of code scanning login
随机推荐
披萨订购设计----简单工厂模式
4、 Database design
Redis学习笔记—地理信息定位(GEO)
Learn SCI thesis drawing skills (E)
[QNX Hypervisor 2.2用户手册]6.2 网络
Mysql 数据库入门总结
528. Random Pick with Weight
Community article | mosn building subset optimization ideas sharing
636. Exclusive Time of Functions
一元函数求极限三大方法---洛必达法则,泰勒公式
125. Valid Palindrome
How postman does interface testing 1: how to import swagger interface documents
Geoserver添加mongoDB数据源
Testing -- automated testing selenium (about API)
Aiming at the overseas pet market, "grasshand" has developed an intelligent tracking product independent of mobile phones | early project
Linux MySQL installation
[learning resources] understand and love mathematics
类型从属名称的使用必须以“typename”为前缀
Tencent cloud arm server evaluation practice
Isomorphic strings for leetcode topic resolution