美文网首页
Redis之geo

Redis之geo

作者: lenny611 | 来源:发表于2021-08-22 23:57 被阅读0次

    geo命令

    geoadd:添加地理位置

    127.0.0.1:6379> get keys
    (nil)
    127.0.0.1:6379> geoadd city  113.087559 28.251818 ChangSha
    (integer) 1
    127.0.0.1:6379> geoadd city  114.064552 22.548457 ShenZhen
    (integer) 1
    127.0.0.1:6379> geoadd city 104.087045 30.666416 ChengDu
    (integer) 1
    127.0.0.1:6379> geoadd city 106.558434 29.568996 ChongQing
    (integer) 1
    

    geopos:显示经纬度信息

    127.0.0.1:6379> geopos city ChengDu
    1) 1) "104.08704489469528198"
       2) "30.6664164635846177"
    127.0.0.1:6379> geopos city ChongQing
    1) 1) "106.55843228101730347"
       2) "29.56899626404301529"
    

    geodist:显示距离

    127.0.0.1:6379> geodist city ChengDu ChongQing km
    "267.2629"
    127.0.0.1:6379> geodist city ShenZhen ChongQing km 
    "1082.0822"
    

    geohash:返回一个或者多个GEOHASH 表示的元素, 返回 11 个字符 Geohash 字符串

    127.0.0.1:6379> geohash city ShenZhen 
    1) "ws1078g6290"
    

    georedius:指定经纬度作为原点,指定半径,查询在指定范围内的城市,这些城市都是在我们自己的集合里面

    127.0.0.1:6379> georadius city 110 30 500 km
    1) "ChongQing"
    2) "ChangSha"
    

    geoRediusByMember:找出位于指定元素周围的城市

    127.0.0.1:6379> georadiusbymember city ChongQing 300 km
    1) "ChongQing"
    2) "ChengDu"
    

    Geospatial 底层的原理就是使用 Zset 有序集合来实现的。

    geo经纬度的范围:

    有效的经度从-180度到180度。
    有效的纬度从-85.05112878度到85.05112878度。

    Geospatial 应用场景

    1.附近的人
    2.计算距离
    3.定位
    等与位置有关的场景

    相关文章

      网友评论

          本文标题:Redis之geo

          本文链接:https://www.haomeiwen.com/subject/mpqkiltx.html