Redis GEO

用 GEO 存经纬度、算距离、找附近的人。

Beginner
Key PointsGEO 底层是 Sorted Set(经纬度编码成 score),提供附近搜索。

存位置与查询

Shell
GEOADD cities 116.40 39.90 "Beijing" 121.47 31.23 "Shanghai"
GEODIST cities Beijing Shanghai km      # 两点距离(公里)
GEORADIUS cities 116.40 39.90 300 km    # 300km 内的点
Output
1) "Beijing"
2) "Tianjin"
For 'nearby stores / people' you don't need a dedicated geo engine — GEO commands do it in a few lines. Backed by a ZSet, so members dedupe; distances use a WGS84 approximation.

Friends & Partners