Use GEODIST to get the distance between two members of a geospatial index.
The unit defaults to meters and can be set to m, km, ft, or mi. The distance is a great-circle distance computed from the stored positions assuming the Earth is a sphere, so it carries the small error of the geohash encoding and, of course, says nothing about the distance actually travelled on roads. If either member is missing from the index the reply is null.
Syntax#
Arguments#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<key> | Yes | No | Redis key targeted by the command. |
<member1> | Yes | No | First member. |
<member2> | Yes | No | Second member. |
(m | km | ft | mi) | No | No | Distance unit: m (meters), km (kilometers), ft (feet), or mi (miles). Defaults to m when omitted. |
Important points#
- The distance is always returned as a bulk string, in both RESP2 and RESP3. Client libraries commonly decode it to a language number.
Response#
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
| Protocol | Reply |
|---|---|
| RESP2 | Null bulk string or null array or Bulk string |
| RESP3 | Null or Bulk string |
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples#
TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.