diff options
author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-10-18 10:07:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-18 11:07:02 +0300 |
commit | 03a0c312699b3e130e8032a41a9999d709a035b9 (patch) | |
tree | e6205d20a5722a88a9fb5f5354857091abc4076c /redis | |
parent | 46430c2b756df8e6ffe7b33ac52c987a6a9c8cce (diff) | |
download | redis-py-03a0c312699b3e130e8032a41a9999d709a035b9.tar.gz |
Add support to NX XX and CH to `GEOADD` (#1605)
Diffstat (limited to 'redis')
-rw-r--r-- | redis/commands.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/redis/commands.py b/redis/commands.py index 9bd57e8..9dad8a5 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -2904,17 +2904,39 @@ class Commands: return Script(self, script) # GEO COMMANDS - def geoadd(self, name, *values): + def geoadd(self, name, values, nx=False, xx=False, ch=False): """ Add the specified geospatial items to the specified key identified by the ``name`` argument. The Geospatial items are given as ordered members of the ``values`` argument, each item or place is formed by the triad longitude, latitude and name. + + Note: You can use ZREM to remove elements. + + ``nx`` forces ZADD to only create new elements and not to update + scores for elements that already exist. + + ``xx`` forces ZADD to only update scores of elements that already + exist. New elements will not be added. + + ``ch`` modifies the return value to be the numbers of elements changed. + Changed elements include new elements that were added and elements + whose scores changed. """ + if nx and xx: + raise DataError("GEOADD allows either 'nx' or 'xx', not both") if len(values) % 3 != 0: raise DataError("GEOADD requires places with lon, lat and name" " values") - return self.execute_command('GEOADD', name, *values) + pieces = [name] + if nx: + pieces.append('NX') + if xx: + pieces.append('XX') + if ch: + pieces.append('CH') + pieces.extend(values) + return self.execute_command('GEOADD', *pieces) def geodist(self, name, place1, place2, unit=None): """ |