首先需要安装redis3.2以上版本,建议最新
然后安装phpredis扩展.http://pecl.php.net/package/redis

安装phpredis扩展
wget http://pecl.php.net/get/redis-4.0.0.tgz
tar -zxvf redis-4.0.0.tgz
cd redis-4.0.0
/usr/local/php/bin/phpize
make && make install
重启php
public function geo(){
$redis = new \redis();
$redis -> connect('127.0.0.1',6379);
//位置增加
$res= $redis->geoAdd("cs",13.361389,38.115556,'peter',13.361389,38.125566,'peter1');
//位置获取
$redis->geoPos("cs",'peter');
//两点之间的距离
$redis->geoDist("cs",'peter','peter1','m');
//范围查询:200m内的坐标点
$potion=['WITHHASH','count'=>2,'ASC'];//空字符串 返回key,WITHCOORD 返回key和经纬度 WITHHASH 返回key和距离 count返回几条 ASC和DESC降序和升序
return $redis->geoRadius("cs",13.361389,38.115556,'200','m',$potion); //m 米 km千米
}
网友评论