Skip to content

Commit

Permalink
Implement GEOSEARCHSTORE
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Feb 25, 2023
1 parent 55ba9a0 commit 77bac4b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/redis-commands/Redis.md
Expand Up @@ -1218,13 +1218,13 @@ A read-only variant for GEORADIUS

Query a sorted set representing a geospatial index to fetch members inside an area of a box or a circle.

### [GEOSEARCHSTORE](https://redis.io/commands/geosearchstore/)

### Unsupported geo commands
> To implement support for a command, see [here](/guides/implement-command/)
Query a sorted set representing a geospatial index to fetch members inside an area of a box or a circle, and store the result in another key.

#### [GEOSEARCHSTORE](https://redis.io/commands/geosearchstore/) <small>(not implemented)</small>

Query a sorted set representing a geospatial index to fetch members inside an area of a box or a circle, and store the result in another key.
### Unsupported geo commands
> To implement support for a command, see [here](/guides/implement-command/)

## hash commands
Expand Down
16 changes: 16 additions & 0 deletions fakeredis/commands_mixins/geo_mixin.py
Expand Up @@ -202,3 +202,19 @@ def geosearch(self, key, *args):
return self.georadiusbymember_ro(key, frommember, radius, *left_args)
else:
return self.georadius_ro(key, long, lat, radius, *left_args)

@command(name='GEOSEARCHSTORE', fixed=(bytes, Key(ZSet),), repeat=(bytes,))
def geosearchstore(self, dst, src, *args):
(frommember, (long, lat), radius, storedist), left_args = extract_args(
args, ('*frommember', '..fromlonlat', '.byradius', 'storedist'),
error_on_unexpected=False, left_from_first_unexpected=False)
if frommember is None and long is None:
raise SimpleError(msgs.SYNTAX_ERROR_MSG)
if frommember is not None and long is not None:
raise SimpleError(msgs.SYNTAX_ERROR_MSG)
additional = [b'storedist', dst] if storedist else [b'store', dst]

if frommember:
return self.georadiusbymember(src, frommember, radius, *left_args, *additional)
else:
return self.georadius(src, long, lat, radius, *left_args, *additional)
1 change: 1 addition & 0 deletions test/test_mixins/test_geo_commands.py
Expand Up @@ -216,3 +216,4 @@ def test_geosearch(r: redis.Redis):
assert r.geosearch("barcelona", member="place3", radius=100, unit="km", count=2) == [b"place3", b"place2"]
assert r.geosearch("barcelona", member="place3", radius=100, unit="km", count=1, any=1)[0] in [
b"place1", b"place3", b"place2"]

0 comments on commit 77bac4b

Please sign in to comment.