GEOSEARCHSTORE(3valkey)

๐Ÿ“ฆ
version 9.0.6 ยท 2 versions
, in fedora 44

๐Ÿ’– GEOSEARCHSTORE โ€” the valkey manual page, bestie edition โœจ

okay so bestie, this is GEOSEARCHSTORE from the Valkey Command Manual, and it's genuinely one of my faves ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

geosearchstore โ€” queries a geospatial index for members inside an area of a box, a circle, or a polygon, and optionally stores the result ๐Ÿ’…


โœจ SYNOPSIS โœจ

GEOSEARCHSTORE destination source [FROMMEMBER member | FROMLONLAT
longitude latitude] <BYRADIUS radius <M | KM | FT | MI> | BYBOX width
height <M | KM | FT | MI> | BYPOLYGON num-vertices longitude latitude
[longitude latitude ...]> [ASC | DESC] [COUNT count [ANY]] [STOREDIST]

likeโ€ฆ look at her. she's doing so much. and she's doing it flawlessly ๐Ÿ˜Œ


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so this one is literally GEOSEARCH from valkey-geosearch(7), except she stores the result in the destination key instead of just handing it back to you. it's giving "search but make it permanent" ๐Ÿ’พโœจ

this command replaces the now deprecated GEORADIUS from valkey-georadius(7) and GEORADIUSBYMEMBER from valkey-georadiusbymember(7). rip to them, they were iconic but they're done now ๐Ÿ™ˆ

by default, it stores the results in the destination sorted set with their geospatial information โ€” so the geo vibes come along for the ride ๐ŸŒ

when you use the STOREDIST option tho? that's when it gets fun. the command stores the items in a sorted set populated with their distance from the center of the circle, box or polygon, as a floating-point number, in the same unit you specified for that shape. no cap, the unit carries over. so if you said km, you get km. periodt ๐Ÿ“


๐Ÿ’Œ REPLY ๐Ÿ’Œ

valkey-protocol(7) Integer reply: the number of elements in the resulting set ๐Ÿ”ข


๐Ÿ”ฅ COMPLEXITY ๐Ÿ”ฅ

O(N+log(M)) where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter, and M is the number of items inside the shape ๐Ÿงฎ

(not me actually understanding big-O now, growth ๐Ÿ’…)


๐Ÿ‘‘ ACL CATEGORIES ๐Ÿ‘‘

  • @geo
  • @slow
  • @write

๐ŸŒˆ HISTORY ๐ŸŒˆ

  • Available since: 6.2.0 โ€” a baby ๐Ÿผ
  • Changed in 7.0.0: Added support for uppercase unit names. (KM girlies rise up ๐Ÿซถ)
  • Changed in 9.0.0: Added support for the BYPOLYGON option. ๐Ÿ”บ

๐ŸŽ€ EXAMPLES ๐ŸŽ€

watch her work, bestie:

127.0.0.1:6379> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
127.0.0.1:6379> GEOADD Sicily 12.758489 38.788135 "edge1"   17.241510 38.788135 "edge2"
(integer) 2
127.0.0.1:6379> GEOSEARCHSTORE key1 Sicily FROMLONLAT 15 37 BYBOX 400 400 km ASC COUNT 3
(integer) 3
127.0.0.1:6379> GEOSEARCH key1 FROMLONLAT 15 37 BYBOX 400 400 km ASC WITHCOORD WITHDIST WITHHASH
1) 1) "Catania"
   2) "56.4413"
   3) (integer) 3479447370796909
   4) 1) "15.08726745843887329"
      2) "37.50266842333162032"
2) 1) "Palermo"
   2) "190.4424"
   3) (integer) 3479099956230698
   4) 1) "13.36138933897018433"
      2) "38.11555639549629859"
3) 1) "edge2"
   2) "279.7403"
   3) (integer) 3481342659049484
   4) 1) "17.24151045083999634"
      2) "38.78813451624225195"
127.0.0.1:6379> GEOSEARCHSTORE key2 Sicily FROMLONLAT 15 37 BYBOX 400 400 km ASC COUNT 3 STOREDIST
(integer) 3
127.0.0.1:6379> ZRANGE key2 0 -1 WITHSCORES
1) "Catania"
2) "56.4412578701582"
3) "Palermo"
4) "190.44242984775784"
5) "edge2"
6) "279.7403417843143"

see how key2 is just distances now because of STOREDIST? she ate that fr fr ๐Ÿ”ฅ


๐Ÿงš SEE ALSO ๐Ÿงš

geoadd(3valkey), geodist(3valkey), geohash(3valkey), geopos(3valkey), georadius(3valkey), georadiusbymember(3valkey), georadiusbymember_ro(3valkey), georadius_ro(3valkey), geosearch(3valkey)


okay that's the whole page, you read all of it, I'm so proud of you ๐Ÿฅน๐Ÿ’œ go store some geo data bestie

this was GEOSEARCHSTORE(3valkey), from version 9.0.0, dated 2025-10-21 โ€” mwah, catch you in the next manpage ๐Ÿ’…๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from