zoukankan      html  css  js  c++  java
  • 关于php redis的geocoding函数

    在php的redis扩展官方github上,文档的最下面的确存在geocoding的函数说明。但是笔者尝试调用geoAdd函数时,返回值一直为false。就纳闷了,是使用的姿势不对,还是存在其它问题?所以,笔者确认了本地的php扩展版本与redis-server的版本,均为5.0以上,版本无误 。接着,在代码中用method_exists确认了扩展的类中确实存在geoAdd函数,并且用redis-cli确认服务端也支持geoadd命令。至此,完全可以判断官网扩展中geo函数的确存在问题。

    在这种情况下,geocoding函数对笔者相对重要,所以最后采用了rawCommand函数直接调用redis原始的命令,特此备忘:

    $redis->del("citys");
    //$result=$redis->geoAdd("myplaces", 116.40378, 39.91544);
    $redis->rawCommand('geoadd', 'citys', '116.40', '39.90', 'beijing','121.47', '31.23', 'shanghai');
    $redis->rawCommand('geoadd', 'citys', '114.30', '30.60', 'wuhan');
    //$redis->rawCommand("zrem","citys","wuhan");
    
    
    var_export($redis->rawCommand('geopos', 'citys', 'beijing'));
    echo '<br />';
    var_export($redis->rawCommand('geohash', 'citys', 'shanghai', 'wuhan'));
    
    //查询以经纬度为114,30为圆心,100千米范围内的成员
    echo '<br />georadius';
    var_export($redis->rawCommand('georadius', 'citys', '114', '30', '1000', 'km'));
    
    //WITHCOORD表示获取成员经纬度
    echo '<br />';
    var_export($redis->rawCommand('georadius', 'citys', '114', '30', '100', 'km', 'WITHCOORD'));
    
    //WITHDIST表示获取到圆心的距离
    echo '<br />';
    var_export($redis->rawCommand('georadius', 'citys', '114', '30', '100', 'km', 'WITHDIST'));
    
    //查询以武汉为圆心,100千米范围内的成员
    echo '<br />';
    var_export($redis->rawCommand('georadiusbymember', 'citys', 'wuhan', '100', 'km'));

    笔者觉得奇怪,网上那么多文章,都是直接调用geocoding函数,还附上大段大段的使用说明。各位是真的调通了?还是天下文章一大抄?

  • 相关阅读:
    Vue 2.x windows环境下安装
    VSCODE官网下载缓慢或下载失败 解决办法
    angular cli 降级
    Win10 VS2019 设置 以管理员身份运行
    XSHELL 连接 阿里云ECS实例
    Chrome浏览器跨域设置
    DBeaver 执行 mysql 多条语句报错
    DBeaver 连接MySql 8.0 报错 Public Key Retrieval is not allowed
    DBeaver 连接MySql 8.0报错 Unable to load authentication plugin 'caching_sha2_password'
    Linux系统分区
  • 原文地址:https://www.cnblogs.com/ddcoder/p/12515815.html
Copyright © 2011-2022 走看看