GEODIST(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– GEODIST β€” the valkey manual page, but make it cute ✨

okay bestie, welcome to GEODIST(3valkey) πŸ’… you're in the valkey command manual, section 3, and today we're measuring the literal distance between two lil members of a geospatial index. it's giving long distance relationship but make it math πŸ¦‹


🌸 NAME 🌸

geodist β€” returns the distance between two members of a geospatial index. that's it. that's the whole job. and she does it flawlessly. πŸ‘‘


✨ SYNOPSIS ✨

GEODIST key member1 member2 [M | KM | FT | MI]

like… three args and an optional unit. so simple. so clean. no cap. πŸŽ€


πŸ’œ DESCRIPTION πŸ’œ

so here's the tea β˜•: GEODIST returns the distance between two members inside the geospatial index that's represented by the sorted set. yes, the sorted set. the whole index lives in there. iconic behavior honestly.

you give it a sorted set that represents a geospatial index β€” one that you populated with the valkey-geoadd(7) GEOADD command β€” and the command hands you back the distance between the two members you named, in whatever unit you asked for. 🫢

if one or both of the members are missing, the command returns NULL. not an error, not a vibe, just NULL. πŸ’€

the unit has to be one of these, and it defaults to meters:

  • m for meters. (the default, the og, the moment)
  • km for kilometers.
  • mi for miles.
  • ft for feet.

and lowkey important: the distance is computed assuming that the Earth is a perfect sphere, so errors up to 0.5% are possible in edge cases. she's a sphere truther. that's just how it is 🌈


πŸ”₯ REPLY πŸ”₯

RESP2

one of the following, bestie:

  • valkey-protocol(7) Nil reply: one or both of the elements are missing.
  • valkey-protocol(7) Bulk string reply: distance as a double (represented as a string) in the specified units.

RESP3

one of the following, also bestie:

  • valkey-protocol(7) Null reply: one or both of the elements are missing.
  • valkey-protocol(7) Bulk string reply: distance as a double (represented as a string) in the specified units.

see how RESP3 said Null instead of Nil? that's the whole difference. the more you know πŸ’«


πŸ‘‘ COMPLEXITY πŸ‘‘

O(1)

constant time. instant. no waiting. main character energy fr fr. ⭐


πŸŽ€ ACL CATEGORIES πŸŽ€

@geo @read @slow

three little tags, all accounted for πŸ’–


πŸ¦‹ HISTORY πŸ¦‹

  • Available since: 3.2.0

she's been here since 3.2.0 and she's been serving ever since πŸ™ˆ


🌟 EXAMPLES 🌟

here's the whole thing in action, verbatim, don't touch a character:

127.0.0.1:6379> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
127.0.0.1:6379> GEODIST Sicily Palermo Catania
"166274.1516"
127.0.0.1:6379> GEODIST Sicily Palermo Catania km
"166.2742"
127.0.0.1:6379> GEODIST Sicily Palermo Catania mi
"103.3182"
127.0.0.1:6379> GEODIST Sicily Foo Bar
(nil)

Palermo to Catania, in meters, kilometers, and miles β€” and then Foo and Bar which don't even exist, so (nil). we've all been Foo and Bar at some point 😭


🌈 SEE ALSO 🌈

the whole geo friend group, all together, no one left out 🫢


okay that's the whole page, you ate it, you understood it, periodt. this cutie was brought to you by Valkey 9.0.0, dated 2025-10-21 πŸ’…βœ¨ go measure something, bestie 🌸

πŸ“¦ where this page comes from