diff options
author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-10-14 16:05:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-14 16:05:17 +0200 |
commit | 298d72267922e01ed325ef937692cbf879c2528e (patch) | |
tree | 26801fa5174c5752713beb34b51f0a5fc08aec60 /redis/commands.py | |
parent | eeac2529e91d691cc0d22206b81cef15909b73ed (diff) | |
parent | 90468846acb7812df6419d54a9c191156e170516 (diff) | |
download | redis-py-298d72267922e01ed325ef937692cbf879c2528e.tar.gz |
Merge pull request #1606 from AvitalFineRedis/GEORADIUS_count_any
Add support to ANY to GEOSEARCHSTORE and to GEOSEARCH
Diffstat (limited to 'redis/commands.py')
-rw-r--r-- | redis/commands.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/redis/commands.py b/redis/commands.py index dbc188c..baf5239 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -2932,7 +2932,7 @@ class Commands: def georadius(self, name, longitude, latitude, radius, unit=None, withdist=False, withcoord=False, withhash=False, count=None, - sort=None, store=None, store_dist=None): + sort=None, store=None, store_dist=None, any=False): """ Return the members of the specified key identified by the ``name`` argument which are within the borders of the area specified @@ -2966,11 +2966,12 @@ class Commands: unit=unit, withdist=withdist, withcoord=withcoord, withhash=withhash, count=count, sort=sort, store=store, - store_dist=store_dist) + store_dist=store_dist, any=any) def georadiusbymember(self, name, member, radius, unit=None, withdist=False, withcoord=False, withhash=False, - count=None, sort=None, store=None, store_dist=None): + count=None, sort=None, store=None, store_dist=None, + any=False): """ This command is exactly like ``georadius`` with the sole difference that instead of taking, as the center of the area to query, a longitude @@ -2982,7 +2983,7 @@ class Commands: withdist=withdist, withcoord=withcoord, withhash=withhash, count=count, sort=sort, store=store, - store_dist=store_dist) + store_dist=store_dist, any=any) def _georadiusgeneric(self, command, *args, **kwargs): pieces = list(args) @@ -2993,21 +2994,26 @@ class Commands: else: pieces.append('m',) + if kwargs['any'] and kwargs['count'] is None: + raise DataError("``any`` can't be provided without ``count``") + for arg_name, byte_repr in ( - ('withdist', b'WITHDIST'), - ('withcoord', b'WITHCOORD'), - ('withhash', b'WITHHASH')): + ('withdist', 'WITHDIST'), + ('withcoord', 'WITHCOORD'), + ('withhash', 'WITHHASH')): if kwargs[arg_name]: pieces.append(byte_repr) - if kwargs['count']: - pieces.extend([b'COUNT', kwargs['count']]) + if kwargs['count'] is not None: + pieces.extend(['COUNT', kwargs['count']]) + if kwargs['any']: + pieces.append('ANY') if kwargs['sort']: if kwargs['sort'] == 'ASC': - pieces.append(b'ASC') + pieces.append('ASC') elif kwargs['sort'] == 'DESC': - pieces.append(b'DESC') + pieces.append('DESC') else: raise DataError("GEORADIUS invalid sort") @@ -3140,7 +3146,8 @@ class Commands: if kwargs['any']: pieces.append(b'ANY') elif kwargs['any']: - raise DataError("GEOSEARCH any can't be provided without count") + raise DataError("GEOSEARCH ``any`` can't be provided " + "without count") # other properties for arg_name, byte_repr in ( |