-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: adds GEOSEARCHSTORE command #1581
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2708,7 +2708,7 @@ async def geosearch( | |
Since: Redis version 6.2.0. | ||
""" | ||
args = _create_geosearch_args( | ||
key, | ||
[key], | ||
search_from, | ||
seach_by, | ||
order_by, | ||
|
@@ -2723,6 +2723,72 @@ async def geosearch( | |
await self._execute_command(RequestType.GeoSearch, args), | ||
) | ||
|
||
async def geosearchstore( | ||
self, | ||
destination: str, | ||
source: str, | ||
search_from: Union[str, GeospatialData], | ||
search_by: Union[GeoSearchByRadius, GeoSearchByBox], | ||
count: Optional[GeoSearchCount] = None, | ||
store_dist: bool = False, | ||
) -> int: | ||
""" | ||
Searches for members in a sorted set stored at `key` representing geospatial data within a circular or rectangular area and stores the result in `destination`. | ||
If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created. | ||
|
||
To get the result directly, see `geosearch`. | ||
|
||
Note: | ||
When in cluster mode, both `source` and `destination` must map to the same hash slot. | ||
|
||
Args: | ||
destination (str): The key to store the search results. | ||
source (str): The key of the sorted set representing geospatial data to search from. | ||
search_from (Union[str, GeospatialData]): The location to search from. Can be specified either as a member | ||
from the sorted set or as a geospatial data (see `GeospatialData`). | ||
search_by (Union[GeoSearchByRadius, GeoSearchByBox]): The search criteria. | ||
For circular area search, see `GeoSearchByRadius`. | ||
For rectangular area search, see `GeoSearchByBox`. | ||
count (Optional[GeoSearchCount]): Specifies the maximum number of results to store. See `GeoSearchCount`. | ||
If not specified, stores all results. | ||
store_dist (bool): Determines what is stored as the sorted set score. Defaults to False. | ||
- If set to False, the geohash of the location will be stored as the sorted set score. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is geohash stored if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If store_dist is false - the geohash is stored as score There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please update the doc? It was unclear for me. |
||
- If set to True, the distance from the center of the shape (circle or box) will be stored as the sorted set score. | ||
The distance is represented as a floating-point number in the same unit specified for that shape. | ||
|
||
Returns: | ||
int: The number of elements in the resulting sorted set stored at `destination`. | ||
|
||
Examples: | ||
>>> await client.geoadd("my_geo_sorted_set", {"Palermo": GeospatialData(13.361389, 38.115556), "Catania": GeospatialData(15.087269, 37.502669)}) | ||
>>> await client.geosearchstore("my_dest_sorted_set", "my_geo_sorted_set", "Catania", GeoSearchByRadius(175, GeoUnit.MILES)) | ||
2 # Number of elements stored in "my_dest_sorted_set". | ||
>>> await client.zrange_withscores("my_dest_sorted_set", RangeByIndex(0, -1)) | ||
{"Palermo": 3479099956230698.0, "Catania": 3479447370796909.0} # The elements within te search area, with their geohash as score. | ||
>>> await client.geosearchstore("my_dest_sorted_set", "my_geo_sorted_set", GeospatialData(15, 37), GeoSearchByBox(400, 400, GeoUnit.KILOMETERS), store_dist=True) | ||
2 # Number of elements stored in "my_dest_sorted_set", with distance as score. | ||
>>> await client.zrange_withscores("my_dest_sorted_set", RangeByIndex(0, -1)) | ||
{"Catania": 56.4412578701582, "Palermo": 190.44242984775784} # The elements within te search area, with the distance as score. | ||
|
||
Since: Redis version 6.2.0. | ||
""" | ||
args = _create_geosearch_args( | ||
[destination, source], | ||
search_from, | ||
search_by, | ||
None, | ||
count, | ||
False, | ||
False, | ||
False, | ||
store_dist, | ||
) | ||
|
||
return cast( | ||
int, | ||
await self._execute_command(RequestType.GeoSearchStore, args), | ||
) | ||
|
||
async def zadd( | ||
self, | ||
key: str, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3