Redis Geo模块命令:
1)geoadd:将给定的位置对象(纬度、经度、名字)添加到指定的key;
2)geopos:从key里面返回所有给定位置对象的位置(经度和纬度);
3)geodist:返回两个给定位置之间的距离;
4)geohash:返回一个或多个位置对象的geohash表示;
5)georadius:以给定的经纬度为中心,返回目标集合中与中心的距离不超过给定最大距离的所有位置对象;
6)georadiusbymember:以给定的位置对象为中心,返回与其距离不超过给定最大距离的所有位置对象。
geoadd key long lat member [longitude latitude member]
127.0.0.1:6379> geoadd china:city 121.47 31.23 shanghai
(integer) 1
127.0.0.1:6379> geoadd china:city 116.40 39.90 beijing
(integer) 1
127.0.0.1:6379> geoadd chaina:city 118.78 32.07 nanjing
(integer) 1
返回值 1表示添加成功 1 条记录。
geopos key member [member ...]
127.0.0.1:6379> geopos china:city beijing
1) 1) "116.39999896287918091"
2) "39.90000009167092543"
127.0.0.1:6379> geopos china:city shanghai
1) 1) "121.47000163793563843"
2) "31.22999903975783553"
geodist key member1 member2 [unit]
其中unit为可选参数,可选以下四种
-m:代表单位米(默认)
- km:代表单位千米
- mi:代表单位英里
- ft:代表单位尺
127.0.0.1:6379> geodist china:city beijing shanghai
"1067378.7564"
georadius key longitude latitude radius m|km|ft|mi [withcoord] [withdist] [withhash] [count count]
127.0.0.1:6379> georadius china:city 121.47 31.23 1000 km withdist
1) 1) "shanghai"
2) "0.0002"
georadiusbymember key member radius m|km|ft|mi [withcoord] [withdist] [withhash] [count count]
127.0.0.1:6379> georadiusbymember china:city shanghai 10000 km withdist
1) 1) "shanghai"
2) "0.0000"
2) 1) "beijing"
2) "1067.3788"
georadiusbymember key member radius m|km|ft|mi [withcoord] [withdist] [withhash] [count count]
127.0.0.1:6379> georadiusbymember china:city shanghai 10000 km withcoord
1) 1) "shanghai"
2) 1) "121.47000163793563843"
2) "31.22999903975783553"
2) 1) "beijing"
2) 1) "116.39999896287918091"
2) "39.90000009167092543"
zrem key member
127.0.0.1:6379> zrem china:city beijing
(integer) 1
geohash key member [member ...]
127.0.0.1:6379> geohash china:city shanghai
1) "wtw3sj5zbj0"