一. Redis的GEO特性

Redis3.2版本提供了GEO功能,支持存储地理位置信息用来实现诸如摇一摇,附近位置这类依赖于地理位置信息的功能。
二. 命令
2.1 增加地理位置信息

命令:geoadd key longitude latitude member[longitude latitude member…]

例如:geoadd cities:locations 116.28 39.55 beijing 117.12 39.08 tianjin114.29 38.02 shijiazhuang 118.01 39.38 tangshan 115.29 38.51 baoding

返回:4
2.2 获取地理位置信息

命令:geopos key member[member…]

例如:geopos cities:locations tianjin beijing

返回:

1) 1) "117.12000042200088501"

2) "39.0800000535766543"

2) 1) "116.28000229597091675"

2) "39.5500007245470826"
2.3 获取两个地理位置的距离

命令:geodist key member1 member2 [unit]

选项:unit:单位,默认为m(米)

m:米

km:千米

mi:英里

ft:尺

例如:

10.3.34.101:6378> geodistcities:locations beijing tianjin

"89206.0576"

10.3.34.101:6378> geodistcities:locations beijing tianjin km

"89.2061"

10.3.34.101:6378> geodistcities:locations beijing tianjin m

"89206.0576"

10.3.34.101:6378> geodist cities:locationsbeijing tianjin mi

"55.4302"

10.3.34.101:6378> geodistcities:locations beijing tianjin ft

"292670.7926"

2.4 获取指定位置范围内的地理信息位置集合

(1)中心为坐标

georadius key longtitude latitude radiumm|km|mi|ft [withcoord][withdist][withhash][COUNT count][asc|desc][store key][storedistkey]

(2)中心为成员

georadius key member radium m|km|mi|ft [withcoord][withdist][withhash][COUNTcount][asc|desc][store key][storedist key]

选项:

withcoord:返回结果中包含经纬度

withdist:返回结果中包含离中心节点位置的距离

withhash:返回结果中包含geohash

Count count:返回结果的数量

asc|desc:按照离中心节点的距离做升序或者降序

store key:将返回结果的地理位置信息保存在指定键中

stroedist key:将返回结果离中心点的距离保存在指定键中

例如:

10.3.34.101:6378> georadiusbymembercities:locations beijing 150 km

1) "beijing"

2) "tianjin"

3) "tangshan"

4) "baoding"

10.3.34.101:6378> georadiusbymembercities:locations beijing 15 km

2.5 获取geohash

geohash将二维经纬度转换为一维字符串,字符串越长,精度越高,当长度为9时,精度在2米左右。

Geohash长度

精度

1

2500

2

630

3

78

4

20

5

2.4

6

0.61

7

0.076

8

0.019

9

0.002

命令:geohash key member[member…]

例如:geohash cities:locations beijing

1)      "wx48ypbe2q0"
2.6 删除地理位置信息

GEO没有删除成员的命令,但是因为GEO的底层实现是zset,所以可以借用zrem命令实现对地理位置信息的删除。

命令:zrem key member
---------------------
作者:大道化简
来源:CSDN
原文:https://blog.csdn.net/sunhuiliang85/article/details/75020341
版权声明:本文为博主原创文章,转载请附上博文链接!

最新文章

  1. 关于 DWZ 弹出框
  2. 杂记- 3W互联网的圈子,大数据敏捷BI与微软BI的前端痛点
  3. 用js获取当前页面的url的相关信息方法
  4. Visual Studio2012中搭建WCF项目
  5. motan源码分析九:开关
  6. java创建XML及开源DOM4J的使用
  7. <ListView>分列显示
  8. 图文详解如何快捷搭建LNMP服务环境
  9. [OpenCV]拓展图像边界
  10. v-cloak的用法和注意事项
  11. node版本升级参考
  12. WCF-Oracel适配器针对UDT的使用配置与注意事项
  13. idea新建一个spring项目,图解
  14. python 的包的导入
  15. windows下vc编译和debug nginx
  16. 解决导入Android例子时“Unable to resolve target 'android-x' ”的错误
  17. 微信小程序连续动画
  18. cordova打包APK,SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode ...
  19. Django - 模型层 - 上
  20. .NET:命令行解析器介绍

热门文章

  1. Web响应的提高
  2. leetcode-158周赛-5224-掷筛子模拟
  3. JZOJ5146:港湾
  4. 1 visual studio code 配置C++开发环境 (windows 开发环境)
  5. mysql最新版与mysql5.6的兼容问题
  6. Python module中的全局变量
  7. ionic-CSS:ionic tab(选项卡)
  8. 如何在windows上把你的项目提交到github(转载)
  9. Hbase启动的时候出现:[RpcServer.handler=28,port=60000] ipc.RpcServer: RpcServer.handler=28,port=60000: exiting,master.HMasterCommandLine: Master exiting
  10. Python3数据科学入门与实践✍✍✍