自Redis 3.2开始,Redis基于geohash和有序集合提供了地理位置相关功能。 Redis Geo模块包含了以下6个命令:
127.0.0.1:6379> geoadd mypos 120.000000 30.000000 "me"
(integer) 1
127.0.0.1:6379> geoadd mypos 120.000000 31.000000 "lili" 121.000000 32.000000 "lilei"
(integer) 2
127.0.0.1:6379> geopos mypos me
1) 1) "120.00000089406967"
2) "30.000000249977013"
m
米 km
千米 mi
英里 ft
英尺127.0.0.1:6379> geodist mypos me lili
"111226.3808"
127.0.0.1:6379> geodist mypos me lili m
"111226.3808"
127.0.0.1:6379> geodist mypos me lili km
"111.2264"
127.0.0.1:6379> geodist mypos me lili mi
"69.1130"
127.0.0.1:6379> geodist mypos me lili ft
"364915.9475"
127.0.0.1:6379> geodist mypos lili lilei
"146166.0591"
127.0.0.1:6379> geohash mypos lili lilei
1) "wtt26emk4e0"
2) "wtwn13mt820"
127.0.0.1:6379> georadius mypos 119 30 120 km
1) "me"
127.0.0.1:6379> georadius mypos 121 31 200 km
1) "me"
2) "lili"
3) "lilei"
127.0.0.1:6379> georadiusbymember mypos lili 120 km
1) "lili"
2) "me"
127.0.0.1:6379> georadiusbymember mypos me 200 km
1) "me"
2) "lili"
127.0.0.1:6379> georadiusbymember mypos lilei 200 km
1) "lilei"
2) "lili"