Introduction
The Geo command family is designed for storing and spatially querying geographic location information. It is implemented at the underlying layer using the Geohash encoding of Sorted Sets. This command family is suitable for scenarios in LBS (Location-Based Services), such as "people nearby," store lookup, and delivery range calculation. Its core commands can be categorized into the following three types based on their features:
Writing and Querying Locations
GEOADD: Writes the longitude and latitude coordinates along with the member name to the underlying Sorted Set.
GEOPOS: Returns the geographic coordinates of stored members.
GEODIST: Calculates the straight-line distance between two members and supports four distance units: m (meters), km (kilometers), mi (miles), and ft (feet).
Circular Range Query (Redis 3.2+)
GEORADIUS: Searches for nearby members within a specified radius from a given coordinate point. It supports sorting by distance and returning distance/coordinates/Geohash.
GEORADIUSBYMEMBER: Searches within the same logical set using an existing member as the center point.
General Spatial Query (Redis 6.2+ / Valkey 8.0+)
GEOSEARCH: Searches for members within a circular or rectangular area, serving as a unified replacement for GEORADIUS / GEORADIUSBYMEMBER. GEOSEARCHSTORE: Stores the search results into a new key, supporting the persistence of query results.
Command Support Overview
Basic Commands: geoadd, geohash, geopos, geodist, georadius, georadiusbymember. These commands are supported by the standard and cluster architectures of Redis versions 4.0, 5.0, 6.2, and 7.0, as well as Valkey versions 8.0 and 9.0.
geosearch, geosearchstore commands: These commands are supported only by Redis versions 6.2 and 7.0, and Valkey versions 8.0 and 9.0. Valkey 9.0 adds the BYPOLYGON option, which supports spatial queries based on custom polygon areas.
Cross-Slot Restriction: Geo family commands do not involve cross-slot access scenarios.
Command Compatibility Matrix
The support status of Geo family commands across different versions and architectures is shown in the table below (✓ indicates supported, ✗ indicates not supported, and — indicates that the command does not involve a cross-slot access scenario).
|
geoadd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | — |
geohash | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | — |
geopos | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | — |
geodist | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | — |
georadius | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | — |
georadiusbymember | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | — |
geosearch | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
geosearchstore | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | — |