diff options
author | Paul Spooren <mail@aparcar.org> | 2020-07-22 12:09:12 -1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-22 15:09:12 -0700 |
commit | f001927f91ba3c22cb892bbf1e39b34fd47693bc (patch) | |
tree | 2c632cf9cb0718eae74680ba629bcdb30ac43d7d /redis | |
parent | 75a2cfe6eeca842801372c997a42707b6dca8c05 (diff) | |
download | redis-py-f001927f91ba3c22cb892bbf1e39b34fd47693bc.tar.gz |
LPOS: add new command (#1354)
Added the LPOS command from Redis 6.0.6
Fixes #1353
Diffstat (limited to 'redis')
-rwxr-xr-x | redis/client.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index 9653f7d..5c95e9f 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2030,6 +2030,42 @@ class Redis(object): "Push ``value`` onto the tail of the list ``name`` if ``name`` exists" return self.execute_command('RPUSHX', name, value) + def lpos(self, name, value, rank=None, count=None, maxlen=None): + """ + Get position of ``value`` within the list ``name`` + + If specified, ``rank`` indicates the "rank" of the first element to + return in case there are multiple copies of ``value`` in the list. + By default, LPOS returns the position of the first occurrence of + ``value`` in the list. When ``rank`` 2, LPOS returns the position of + the second ``value`` in the list. If ``rank`` is negative, LPOS + searches the list in reverse. For example, -1 would return the + position of the last occurrence of ``value`` and -2 would return the + position of the next to last occurrence of ``value``. + + If specified, ``count`` indicates that LPOS should return a list of + up to ``count`` positions. A ``count`` of 2 would return a list of + up to 2 positions. A ``count`` of 0 returns a list of all positions + matching ``value``. When ``count`` is specified and but ``value`` + does not exist in the list, an empty list is returned. + + If specified, ``maxlen`` indicates the maximum number of list + elements to scan. A ``maxlen`` of 1000 will only return the + position(s) of items within the first 1000 entries in the list. + A ``maxlen`` of 0 (the default) will scan the entire list. + """ + pieces = [name, value] + if rank is not None: + pieces.extend(['RANK', rank]) + + if count is not None: + pieces.extend(['COUNT', count]) + + if maxlen is not None: + pieces.extend(['MAXLEN', maxlen]) + + return self.execute_command('LPOS', *pieces) + def sort(self, name, start=None, num=None, by=None, get=None, desc=False, alpha=False, store=None, groups=False): """ |