GEOPOS(3valkey)

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

✨ NAME ✨

geopos β€” bestie, this one gives you back the longitude and latitude of members from a geospatial index πŸ’– (it's the valkey manual page for GEOPOS, and it's lowkey iconic)


πŸŽ€ SYNOPSIS πŸŽ€

GEOPOS key member [member...]

🌸 DESCRIPTION 🌸

Okay so picture this: you've got a sorted set at key that's secretly a geospatial index, and you wanna know where all your lil members actually are. That's the whole plot. GEOPOS returns the positions (longitude,latitude) of all the specified members of the geospatial index represented by the sorted set at key. πŸ—ΊοΈ

So if you've got a sorted set representing a geospatial index that you filled up using the GEOADD command from valkey-geoadd(7), it's often super useful to get the coordinates of specified members back. BUT β€” and this is the part you need to hear, no cap β€” when the geospatial index is populated via GEOADD, the coordinates get converted into a 52 bit geohash. Which means the coordinates you get back may not be exactly the ones you used to add the elements. Small errors may be introduced. It's giving rounding, but make it geography. 😭

Also the command accepts a variable number of arguments, so it always returns an array of positions β€” even when you only specify a single element. It will not do you the favour of flattening that for you, bestie. πŸ’…


πŸ¦‹ REPLY πŸ¦‹

RESP2

valkey-protocol(7) Array reply: an array where each element is a two elements array representing longitude and latitude (x,y) of each member name passed as argument to the command. Non-existing elements are reported as valkey-protocol(7) Nil reply elements of the array. πŸ•³οΈ

RESP3

valkey-protocol(7) Array reply: an array where each element is a two elements array representing longitude and latitude (x,y) of each member name passed as argument to the command. Non-existing elements are reported as valkey-protocol(7) Null reply elements of the array. πŸ«₯

Same energy, different protocol β€” RESP2 says Nil, RESP3 says Null. Know which one you're on so you don't get confused and spiral. πŸ’€

🌈 COMPLEXITY 🌈

O(1) for each member requested. ✨ Constant time per member, we love a fast queen. πŸ‘‘


πŸ’œ ACL CATEGORIES πŸ’œ

@geo @read @slow


⭐ HISTORY ⭐

  • Available since: 3.2.0

πŸ’… EXAMPLES πŸ’…

127.0.0.1:6379> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
127.0.0.1:6379> GEOPOS Sicily Palermo Catania NonExisting
1) 1) "13.36138933897018433"
   2) "38.11555639549629859"
2) 1) "15.08726745843887329"
   2) "37.50266842333162032"
3) (nil)

See how NonExisting just comes back as (nil)? Yeah. She's not there. She never was. πŸ™ˆ And notice the returned coords aren't character-for-character the ones we fed in β€” that's the geohash situation we talked about. πŸ”₯


🧚 SEE ALSO 🧚


okay that's the whole page, you ate that fr fr 🫢 This was brought to you by Valkey 9.0.0, dated 2025-10-21 β€” go find your friends on a map, bestie, and stay hydrated πŸ“πŸ’–βœ¨

πŸ“¦ where this page comes from