# GEOSEARCHSTORE

> Run a geospatial search and store the matching members in another sorted set.

URL: https://docs.hotkv.com/commands/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
- HotKV Cloud: all plans
- On-Premise: no license needed

`GEOSEARCHSTORE` runs the same search as [GEOSEARCH](https://docs.hotkv.com/commands/geosearch/index.md) 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](https://docs.hotkv.com/commands/zrange/index.md) by distance.

## 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

| 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

```
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) 4
127.0.0.1:6379> GEOSEARCHSTORE near-brussels cities FROMMEMBER brussels BYRADIUS 200 km STOREDIST
(integer) 2
127.0.0.1:6379> ZRANGE near-brussels 0 -1
1) "brussels"
2) "amsterdam"
127.0.0.1:6379> GEOSEARCHSTORE empty cities FROMLONLAT 0 0 BYRADIUS 1 km
(integer) 0
127.0.0.1:6379> EXISTS empty
(integer) 0
```

## Compatibility

Same as Redis 7 and Valkey 8, with the result ordering notes on the
[GEOSEARCH](https://docs.hotkv.com/commands/geosearch/index.md) page (they matter with `COUNT`).

## See also

[GEOSEARCH](https://docs.hotkv.com/commands/geosearch/index.md), [GEOADD](https://docs.hotkv.com/commands/geoadd/index.md), [ZRANGE](https://docs.hotkv.com/commands/zrange/index.md)