Redis(三)——高級用法(GEO地理位置信息)


一、GEO

1.介紹

GEO(地理信息定位):存儲經緯度,計算兩地距離,范圍等

北京:116.28,39.55

天津:117.12,39.08

可以計算天津到北京的距離,天津周圍50km的城市,外賣等

2.5個城市緯度

城市 經度 緯度 簡稱
北京 116.28 39.55 beijing
天津 117.12 39.08 tianjin
石家庄 114.29 38.02 shijiazhuang
唐山 118.01 39.38 tangshan
保定 115.29 38.51 baoding

3.相關命令

geoadd key longitude latitude member   #增加地理位置信息,設置經度 緯度
geoadd cities:locations 116.28 39.55 beijing #把北京地理信息天津到cities:locations中
geoadd cities:locations 117.12 39.08 tianjin
geoadd cities:locations 114.29 38.02 shijiazhuang
geoadd cities:locations 118.01 39.38 tangshan
geoadd cities:locations 115.29 38.51 baoding
    
geopos key member #獲取地理位置信息
geopos cities:locations beijing #獲取北京地理信息
 geodist key member1 member2 [unit]#獲取兩個地理位置的直線距離 unit:m(米) km(千米) mi(英里) ft(尺)
geodist cities:locations beijing tianjin km #北京到天津的距離,89公里

georadius key logitude 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]
#獲取指定位置范圍內的地理位置信息集合
'''
withcoord:返回結果中包含經緯度
withdist:返回結果中包含距離中心節點位置
withhash:返回解雇中包含geohash
COUNT count:指定返回結果的數量
asc|desc:返回結果按照距離中心店的距離做升序/降序排列
store key:將返回結果的地理位置信息保存到指定鍵
storedist key:將返回結果距離中心點的距離保存到指定鍵
'''
georadiusbymember cities:locations beijing 150 km    #獲取距離北京150km范圍內的地方 '''
1) "beijing"
2) "tianjin"
3) "tangshan"
4) "baoding"
'''

4.總結

3.2以后版本才有

geo本質時zset類型

可以使用zset的刪除,刪除指定member:zrem cities:locations beijing


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM