zoukankan      html  css  js  c++  java
  • redis geo使用笔记

    <?php
    
    $redis = new Redis;
    
    $redis->connect('127.0.0.1' , 6379);
    $redis->auth('123456');
    
    $key = 'cities';
    //添加测试数据
    $redis->geoadd($key , '116.40' , '39.90' , 'beijing');
    $redis->geoadd($key , '121.44' , '31.21' , 'shanghai');
    $redis->geoadd($key , '114.27' , '30.57' , 'wuhan');
    $redis->geoadd($key , '106.54' , '29.58' , 'chongqing');
    $redis->geoadd($key , '112.967' , '28.19' , 'changsha');
    
    //获取两个地点的距离,单位:m(米,默认), km(千米), mi(英里), ft(英尺)
    var_dump($redis->geodist($key,'beijing','wuhan','ft'));
    
    //获取成员经纬度
    var_dump($redis->geopos($key,'beijing'));
    
    //获取成员的经纬度hash,geohash表示坐标的一种方法,便于检索和存储
    var_dump($redis->geohash($key,'shanghai', 'wuhan'));
    
    //查询以指定经纬度方圆1000KM的成员
    
    /**
     * 第五个参数:
     * withcoord:返回结果包含经纬度
     * withdist:返回结果包含离中心节点的距离
     * count:返回结果数量
     * asc | desc:返回结果按照离中心位置升序、降序
     * store key:返回结果地理位置信息保存在指定键中
     * storedist key:返回结果离中心节点距离保存在指定的键中
     */
    
    
    var_dump($redis->georadius($key , '100' , '25' , '1000' , 'km'));
    
    //表示获取到指定的距离
    var_dump($redis->georadius($key , '100' , '25' , '1000' , 'km' , ['withcoord']));
    
    //返回结果包含离中心节点的距离
    var_dump($redis->georadius($key , '100' , '25' , '1000' , 'km' , ['withdist']));
    
    //返回结果数量
    var_dump($redis->georadius($key , '100' , '25' , '1000' , 'km' , ['count' => 3]));
    
    //返回结果按照离中心位置升序、降序
    var_dump($redis->georadius($key , '100' , '25' , '3000' , 'km' , ['asc']));//正序
    var_dump($redis->georadius($key , '100' , '25' , '3000' , 'km' , ['desc']));//倒序
    
    //大体上和georadius一样 只是经纬度改为了成员名称
    var_dump($redis->georadiusbymember($key,'wuhan','3000','km'));
  • 相关阅读:
    windows 获取用户的Sid的方法
    sql replace
    jquery ajax超时设置
    tomcat绑定域名
    .Net webservice动态调用
    JAVA SSH 框架介绍
    第一个Nodejs程序
    linux-CentOS6.4下安装oracle11g详解
    CentOS 6.5系统上安装MySQL数据库
    CentOS6.5安装tomcat7
  • 原文地址:https://www.cnblogs.com/tudou1223/p/15420894.html
Copyright © 2011-2022 走看看