Upstash Documentation

GEODIST

Get distance between two members.
2 min read

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#

ArgumentRequiredRepeatableDescription
<key>YesNoRedis key targeted by the command.
<member1>YesNoFirst member.
<member2>YesNoSecond member.
(m | km | ft | mi)NoNoDistance 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.

ProtocolReply
RESP2Null bulk string or null array or Bulk string
RESP3Null or Bulk string
Note

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.

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs