GEOSEARCH
GEOSEARCH key <FROMMEMBER member | FROMLONLAT longitude latitude> <BYRADIUS radius <M | KM | FT | MI> | BYBOX width height <M | KM | FT | MI>> [ASC | DESC] [COUNT count [ANY]] [WITHCOORD] [WITHDIST] [WITHHASH]
- Available since:
- Redis Open Source 6.2.0
- Time complexity:
- O(N+log(M)) where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter and M is the number of items inside the shape
- ACL categories:
-
@read,@geo,@slow, - Compatibility:
- Redis Software and Redis Cloud compatibility
Return the members of a sorted set populated with geospatial information using GEOADD, which are within the borders of the area specified by a given shape. This command extends the GEORADIUS command, so in addition to searching within circular areas, it supports searching within rectangular areas.
This command should be used in place of the deprecated GEORADIUS and GEORADIUSBYMEMBER commands.
Required arguments
key
The name of the key that holds the geospatial index (a sorted set).
Query center point options:
FROMMEMBER member
Use the position of the existing member as the center of the search. Mutually exclusive with FROMLONLAT.
FROMLONLAT longitude latitude
Use the given coordinates as the center of the search. Mutually exclusive with FROMMEMBER.
Query shape options:
BYRADIUS radius M | KM | FT | MI
Search within a circle of the given radius in the specified unit. Mutually exclusive with BYBOX.
BYBOX width height M | KM | FT | MI
Search within an axis-aligned box of the given width and height in the specified unit. Mutually exclusive with BYRADIUS.
Optional arguments
ASC | DESC
Sort the results by distance from the center: nearest first (ASC) or farthest first (DESC).
COUNT count [ANY]
Return at most count matches. With ANY, the command returns as soon as enough matches are found — faster, but the results may be unsorted. Without COUNT, all matching items are returned.
This means that the results returned may not be the ones closest to the specified point, but the effort invested by the server to generate them is significantly less. When ANY is not provided, the command will perform an effort that is proportional to the number of items matching the specified area and sort them, so to query very large areas with a very small COUNT option may be slow even if just a few results are returned.
WITHCOORD
Also return the longitude and latitude of each matching item.
WITHDIST
Also return the distance of each matching item from the center, in the same unit as the radius.
WITHHASH
Also return the raw 52-bit geohash-encoded score of each matching item.
Examples
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Return information
One of the following:
- If no
WITH*option is specified, an Array reply of matched member names - If
WITHCOORD,WITHDIST, orWITHHASHoptions are specified, the command returns an Array reply of arrays, where each sub-array represents a single item:- The distance from the center as a floating point number, in the same unit specified in the radius.
- The Geohash integer.
- The coordinates as a two items x,y array (longitude,latitude).
History
- Starting with Redis version 7.0.0: Added support for uppercase unit names.