操作方法
方法名稱 |
參數 |
說明 |
備注 |
geoAdd |
$key, $locationData |
新增geohash數據 |
$locationData為一個數組,寫法為:[[longitude=>'',latitude=>'',name=>'']] 或者 $locationData[[longitude,latitude,name]] |
geoDist |
$key, $location1, $location2, $unit = 'm' |
返回排序集合表示的地理空間索引中兩個成員之間的距離。 |
|
geoHash |
$key, $location, ...$locations |
返回表示地理空間索引的hash值 |
|
geoPos |
$key, $location1, ...$locations |
返回按鍵處有序集合表示的地理空間索引的所有指定成員的位置(經度,緯度)。 |
|
geoRadius |
$key, $longitude, $latitude, $radius, $unit = 'm', $withCoord = false, $withDist = false, $withHash = false, $count = null, $sort = null, $storeKey = null, $storeDistKey = null |
返回填充了地理空間信息的已排序集合的成員 |
|
geoRadiusByMember |
$key, $location, $radius, $unit = 'm', $withCoord = false, $withDist = false, $withHash = false, $count = null, $sort = null, $storeKey = null, $storeDistKey = null |
該命令與 GEORADIUS 完全相同,唯一的區別在于,它不是以查詢區域的中心為經度和緯度值,而是采用已存在于有序集合所代表的地理空間索引內的成員的名稱。 |
|
基本使用
go(function () {
$redis = new \EasySwoole\Redis\Redis(new \EasySwoole\Redis\Config\RedisConfig([
'host' => '127.0.0.1',
'port' => '6379',
'auth' => 'easyswoole',
'serialize' => \EasySwoole\Redis\Config\RedisConfig::SERIALIZE_NONE
]));;
$key = 'testGeohash';
$redis->del($key);
$data = $redis->geoAdd($key, [
['118.6197800000', '24.88849', 'user1',],
['118.6197800000', '24.88859', 'user2',],
['114.8197800000', '25.88849', 'user3'],
['118.8197800000', '22.88849', 'user4'],
]);
var_dump($data);
$data = $redis->geoDist($key, 'user1', 'user2');
var_dump($data);
$data = $redis->geoHash($key, 'user1', 'user2');
var_dump($data);
$data = $redis->geoPos($key, 'user1', 'user2');
var_dump($data);
$data = $redis->geoRadius($key, '118.6197800000', '24.88849', 100, 'm', false, false, false, null,'desc');
var_dump($data);
$data = $redis->geoRadiusByMember($key, 'user1', 100, 'm', false, false, false, 2,'DESC');
var_dump($data);
});