支持 GEO 系列命令的 Redis 版本從 3.2.0 起開始纔可使用,因此以前版本就不要想了。php
GEOADD key longitude latitude member [longitude latitude member …]
git
key - 存儲在 Redis 中的指定的鍵redis
longitude - 經度函數
latitude - 緯度code
member - 成員名稱排序
<?php $redis->geoadd("city", 117.224311, 39.111515, "天津") // 1 $redis->geoadd("city", 116.40378, 39.91544, "北京", 121.473913, 31.222965, "上海") // 2 ?>
GEOPOS key member [member ...]
索引
key - 存儲在 Redis 中的指定的鍵ci
member - 成員名稱字符串
<?php $redis->geopos("city", "天津") // Array ( [0] => Array ( [0] => 117.22431153059005737 [1] => 39.11151424175071867 ) ) $redis->geopos("city", "天津", "北京") // Array ( [0] => Array ( [0] => 117.22431153059005737 [1] => 39.11151424175071867 ) [1] => Array ( [0] => 116.40378087759017944 [1] => 39.91543907825245441 ) ) ?>
GEODIST key member1 member2 [unit]
hash
key - 存儲在 Redis 中的指定的鍵
member - 成員名稱
unit - 單位 m(米),km(公里),mi(英里),ft(英尺)
<?php $redis->geodist("city","天津", "北京","km") //113.8093 ?>
GEORADIUS key longitude latitude radius unit(m|km|ft|mi) [WITHCOORD] [WITHDIST] [WITHHASH][COUNT count] [ASC|DESC] [STORE key][STOREDIST key]
key - 存儲在 Redis 中的指定的鍵
longitude - 經度
latitude - 緯度
radius - 半徑
unit - 單位 m(米),km(公里),mi(英里),ft(英尺)
WITHCOORD 返回目標的經緯度
WITHDIST 返回距離中心點的距離
WITHHASH 返回 52位 無符號整數的 geohash 有序集合分數
COUNT 返回條數
ASC|DESC 正序排序|倒序排序
<?php $redis->georadius("city", 117.224311, 39.111515, 1000, "km", ['WITHDIST','ASC']) // Array ( [0] => Array ( [0] => 上海 [1] => 958.4076 ) [1] => Array ( [0] => 北京 [1] => 113.8092 ) [2] => Array ( [0] => 天津 [1] => 0.0001 ) ) $redis->georadius("city", 117.224311, 39.111515, 1000, "km", ['WITHCOORD','WITHDIST','ASC','COUNT'=>1]) // Array ( [0] => Array ( [0] => 天津 [1] => 0.0001 [2] => Array ( [0] => 117.22431153059005737 [1] => 39.11151424175071867 ) ) ) ?>
GEORADIUSBYMEMBER key member radius unit(m|km|ft|mi) [WITHCOORD] [WITHDIST] [WITHHASH][COUNT count] [ASC|DESC] [STORE key][STOREDIST key]
key - 存儲在 Redis 中的指定的鍵
member - 成員名稱
radius - 半徑
unit - 單位 m(米),km(公里),mi(英里),ft(英尺)
WITHCOORD 返回目標的經緯度
WITHDIST 返回距離中心點的距離
WITHHASH 返回 52位 無符號整數的 geohash 有序集合分數
COUNT 返回條數
ASC|DESC 正序排序|倒序排序
<?php $redis->georadiusbymember("city", "天津", 200, "km", ['WITHCOORD', 'WITHDIST', 'ASC']) //Array ( [0] => Array ( [0] => 天津 [1] => 0.0000 [2] => Array ( [0] => 117.22431153059005737 [1] => 39.11151424175071867 ) ) [1] => Array ( [0] => 北京 [1] => 113.8093 [2] => Array ( [0] => 116.40378087759017944 [1] => 39.91543907825245441 ) ) ) ?>
GEOHASH key member [member …]
key - 存儲在 Redis 中的指定的鍵
member - 成員名稱
<?php $redis->geohash("city", "天津", "北京") // Array ( [0] => wwgqe801h60 [1] => wx4g0f6sk90 )