GEODIST(3valkey)
π 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 returnsNULL. not an error, not a vibe, justNULL. π
the unit has to be one of these, and it defaults to meters:
mfor meters. (the default, the og, the moment)kmfor kilometers.mifor miles.ftfor 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 π
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 π
geoadd(3valkey)geohash(3valkey)geopos(3valkey)georadius(3valkey)georadiusbymember(3valkey)georadiusbymember_ro(3valkey)georadius_ro(3valkey)geosearch(3valkey)geosearchstore(3valkey)
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
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms