GEOPOS(3valkey)
β¨ 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 π§
geoadd(3valkey)geodist(3valkey)geohash(3valkey)georadius(3valkey)georadiusbymember(3valkey)georadiusbymember_ro(3valkey)georadius_ro(3valkey)geosearch(3valkey)geosearchstore(3valkey)
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
- 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