GEOSEARCHSTORE
GEOSEARCHSTORE destination source <FROMMEMBER member | FROMLONLAT longitude latitude> <BYRADIUS radius <M | KM | FT | MI> | BYBOX width height <M | KM | FT | MI>> [ASC | DESC] [COUNT count [ANY]] [STOREDIST]
- Group
- Geospatial
- Complexity
- O(N + log M), N being the members in the area searched
- Arity
- -8 (at least 8 words, counting the command name)
- Flags
- write
- Keys
- first 1, last 2, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
GEOSEARCHSTORE runs the same search as GEOSEARCH on
the index at source and writes the matches to the sorted set at
destination, replacing whatever the destination held. When nothing matches,
the destination is deleted.
By default each member keeps its position as its score, so the destination is
itself a geospatial index. With STOREDIST, the score is the member’s
distance from the center, in the unit of the shape, so you can read the
results with ZRANGE by distance.
Options
Section titled “Options”The search options are those of GEOSEARCH (FROMMEMBER, FROMLONLAT,
BYRADIUS, BYBOX, ASC, DESC, COUNT, ANY), plus:
| Option | Effect |
|---|---|
STOREDIST |
Store distances instead of positions as scores. |
WITHCOORD, WITHDIST and WITHHASH are not accepted.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Always | Integer: the number of members stored | Integer |
Error replies: those of GEOSEARCH (with GEOSEARCHSTORE in the messages), plus
ERR GEOSEARCHSTORE is not compatible with WITHDIST, WITHHASH and WITHCOORD options.
WRONGTYPE if the source is not a sorted set.
Examples
Section titled “Examples”127.0.0.1:6379> GEOADD cities -0.1276 51.5072 london 2.3522 48.8566 paris 4.3517 50.8503 brussels 4.9041 52.3676 amsterdam(integer) 4127.0.0.1:6379> GEOSEARCHSTORE near-brussels cities FROMMEMBER brussels BYRADIUS 200 km STOREDIST(integer) 2127.0.0.1:6379> ZRANGE near-brussels 0 -11) "brussels"2) "amsterdam"127.0.0.1:6379> GEOSEARCHSTORE empty cities FROMLONLAT 0 0 BYRADIUS 1 km(integer) 0127.0.0.1:6379> EXISTS empty(integer) 0Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8, with the result ordering notes on the
GEOSEARCH page (they matter with COUNT).
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.