GEO
GEO Profile
- Redis 3.2 adding new features
- Function: storing the latitude and longitude, the two calculated distance, range calculation
- Based ZSet achieve
- Delete operation uses
zrem key member
GEO-related commands
1.geoadd key longitude latitude member [lon lat member...]
- Meaning: increased geographic information
- longitude: Longitude
- latitude: Latitude
- member: identification information
2.geopos key member1 [member2...]
- Meaning: acquiring location information
3.geodist key member1 member2 [unit]
- Meaning: get distance of two geographic
- unit ranges
- m (m, default)
- km (kilometers)
- mi The (mi)
- ft (feet)
4.georadius key longitude latitude unit [withcoord] [withdist] [withhash] [COUNT count] [sort] [store key] [storedist key]
- Meaning: given the latitude and longitude as the center position of the element returns included among the center position from all the elements does not exceed a given maximum distance.
- unit ranges
- m (meters)
- km (kilometers)
- mi The (mi)
- ft (feet)
- withcoord: The latitude and longitude position of the element is also returned together
- withdist: Returns the position of the element at the same time, the distance will be returned together. User distance units and given range consistent units
- withhash: in a signed integer of 52, through the return position geohash element encoded ordered set value. For the underlying application or debug little practical effect.
- sort the range
- asc: The central location, returned from near to far in accordance with the way the position of the element
- desc: According to the center position, far from the embodiment according to the return position near the element
- Save location information and return the results to a specified key: store key
- storedist key: returns the result of the distance from the central node saved to the specified key
5.georadiusbymember key member radius unit [withcoord][withdist][withhash][COUNT count][sort][store key][storedist key]
- Meaning: the given element as the center position of the element returns included among the center position all the elements a distance not exceeding the maximum distance given.
- unit ranges
- m (meters)
- km (kilometers)
- mi The (mi)
- ft (feet)
- withcoord: The latitude and longitude position of the element is also returned together
- withdist: Returns the position of the element at the same time, the distance will be returned together. User distance units and given range consistent units
- withhash: in a signed integer of 52, through the return position geohash element encoded ordered set value. For the underlying application or debug little practical effect.
- sort the range
- asc: The central location, returned from near to far in accordance with the way the position of the element
- desc: According to the center position, far from the embodiment according to the return position near the element
- Save location information and return the results to a specified key: store key
- storedist key: returns the result of the distance from the central node saved to the specified key
Show
Since my redis version is 3.0.7, geo feature was introduced after redis-3.2, so here I put a direct demonstration command, not in a heavy redis.
127.0.0.1:6381> geoadd cities:locations 116.28 39.55 beijing
(integer) 1
127.0.0.1:6381> geoadd cities:locations 117.12 39.08 tianjin 114.29 38.02 shijiazhuang 118.01 39.38 tangshan 115.29 38.51 baoding
(integer) 4
127.0.0.1:6381> geopos cities:locations tianjin
1) 1) "117.12000042200088501"
2) "39.0800000535766543"
127.0.0.1:6381> geodist cities:locations tianjin beijing km
"89.2061"
127.0.0.1:6379> georadiusbymember cities:locations beijing 150 km
1) "beijing"
2) "tianjin"
3) "tangshan"
4) "baoding"
Reproduced in: https: //www.jianshu.com/p/bd0164dfd5fe