zoukankan      html  css  js  c++  java
  • RedisGEO

    一. 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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    深入理解Linux修改hostname
    Linux开发环境必备十大开发工具
    管理员必备的几个Linux系统监控工具
    Solaris&&QNX® Neutrino®&&OpenVMS&&FreeBSD&&AIX
    ansible来了
    Cobbler系统安装备用链接
    Web安全
    在Eclipse/STS中使用EclEmma进行覆盖率检查
    C#中使用扩展方法
    Winform中Textbox的使用
  • 原文地址:https://www.cnblogs.com/lxwphp/p/15453723.html
Copyright © 2011-2022 走看看