当前位置:网站首页>Redis principle Geo
Redis principle Geo
2022-07-22 09:26:00 【yangyanping20108】
Redis GEO
Redis GEO It is mainly used to store geographic information , And operate the stored information , This function is available in Redis 3.2 Version added . Used to realize such as attachment location , Shake this kind of function that depends on Geographic Information , It is a great blessing for developers who need to implement these functions .
Redis GEO The operation methods are :
- geoadd: Add geographic coordinates .
- geopos: Get the coordinates of the geographic location .
- geodist: Calculate the distance between two positions .
- georadius: According to the longitude and latitude coordinates given by the user to obtain the geographic location set within the specified range .
- georadiusbymember: According to a location stored in the location set, get the geographic location set within the specified range .
- geohash: Returns the... Of one or more location objects geohash value .
geoadd
geoadd Used to store a specified geospatial location , You can put one or more longitudes (longitude)、 latitude (latitude)、 Location name (member) Add to specified key in .
geoadd The syntax is as follows :geoadd key longitude latitude member [longitude latitude member ...]
The following table shows the longitude and latitude of several cities
City | longitude | latitude | member |
Hefei | 117.17 | 31.52 | hefei |
Anqing | 117.02 | 30.31 | anqing |
Suzhou | 116.58 | 33.38 | suzhou |
127.0.0.1:6379> geoadd cities 117.17 31.52 hefei
(integer) 1
127.0.0.1:6379> geoadd cities 117.02 30.31 anqing
(integer) 1
127.0.0.1:6379> geoadd cities 116.47 33.57 huaibei
(integer) 1
127.0.0.1:6379> geoadd cities 116.58 33.38 suzhou
(integer) 1
geopos
geopos Used from a given key All specified names are returned in (member) The location of ( Longitude and latitude ), There is no return nil.
geopos The syntax is as follows :geopos key member [member ...]
127.0.0.1:6379> geopos cities hefei
1) 1) "117.17000216245651245"
2) "31.519999022318963"
127.0.0.1:6379> geopos cities anqing
1) 1) "117.02000230550765991"
2) "30.30999918248532765"
geodist
geodist Used to return the distance between two given positions .
geodist The syntax is as follows :geodist key member1 member2 [m|km|ft|mi]
127.0.0.1:6379> geodist cities hefei anqing km
"135.3428"
georadius、georadiusbymember
georadius 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 .
georadiusbymember and GEORADIUS command , Can find the elements in the specified range , however georadiusbymember The center point of is determined by a given location element , Instead of using longitude and latitude to determine the center point .
georadius And georadiusbymember The syntax is as follows :
GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key] GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
Parameter description :
- m : rice , Default unit .
- km : km .
- mi : miles .
- ft : feet .
- WITHDIST: While returning location elements , Return the distance between the location element and the center as well .
- WITHCOORD: Return the longitude and dimension of the location element as well .
- 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 .
- COUNT Limit the number of records returned .
- ASC: The search results are sorted from near to far .
- DESC: The search results are sorted from far to near .
127.0.0.1:6379> georadius cities 117 30 200 km withcoord
1) 1) "anqing"
2) 1) "117.02000230550765991"
2) "30.30999918248532765"
2) 1) "hefei"
2) 1) "117.17000216245651245"
2) "31.519999022318963"
geohash
Redis GEO Use geohash To save the coordinates of the geographic location .
geohash Used to get one or more location elements geohash value .
geohash The syntax is as follows :GEOHASH key member [member ...]
127.0.0.1:6379> geohash cities hefei anqing suzhou
1) "wte766096c0"
2) "wt7hqvg2e90"
3) "wtfvuuduwg0"
127.0.0.1:6379> type cities
zset
Delete geographic information
zrem key member
GEO There is no command to delete members , But because GEO The underlying implementation is zset, So you can borrow zrem Command to delete geographic location information .
边栏推荐
猜你喜欢
Programmers' wisdom and courage in those years!!!
How to quickly develop a simple and practical MES system?
飞机躲子弹小游戏案例
SerializationException: Could not read JSON: Unrecognized token “xxx“
如何快速开发一个简单实用的MES系统?
1989-2020年学历结构和计算平均受教育年限数据
Tencent cloud free upgrade.
LeetCode703:数据流中的第 K 大元素
(1) Principle analysis of Tiktok Kwai short video watermarking
程序员那些年的斗智斗勇!!!
随机推荐
文献:案例《电影排行榜》
EasyCVR平台安全扫描提示Go pprof调试信息泄露的解决办法
高频leetcode深搜部分:695. 岛屿的最大面积
1978-2021中国统计年鉴、2003-2019(省、市面板数据)、1999-2019(县域面板数据)
接口文档进化图鉴,有些古早接口文档工具,你可能都没用过
Literature: Axure (brief introduction)
File文件的基本操作
栈和队列常见oj题
Leetcode703: the k-th element in data flow
odoo-js-doAction详解
NCHW转化为NHWC
Axure repeater
大批量数据excel下载—本文作者只试了51万数据的下载,用时7秒
高频leetcode深搜部分:297. 二叉树的序列化与反序列化
LeetCode342:4的幂
String 类
LeetCode1734:解码异或后的排列
快乐数~~~(其实我一点都不快乐) && 丑数
八大(变量)基本类型
Review 后台管理系统实战:请求参数的 2 种封装风格