关于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函数,还附上大段大段的使用说明。各位是真的调通了?还是天下文章一大抄?

 

posted on 2020-03-18 10:29  咚..咚  阅读(216)  评论(0)    收藏  举报

< 2025年7月 >
29 30 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 1 2
3 4 5 6 7 8 9

导航

统计

点击右上角即可分享
微信分享提示