diff options
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/redis/client.py b/redis/client.py index e5cd647..995239e 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2747,7 +2747,7 @@ class Redis: return self.execute_command('XPENDING', name, groupname) def xpending_range(self, name, groupname, min, max, count, - consumername=None): + consumername=None, idle=None): """ Returns information about pending messages, in a range. name: name of the stream. @@ -2756,21 +2756,35 @@ class Redis: max: maximum stream ID. count: number of messages to return consumername: name of a consumer to filter by (optional). + idle: available from version 6.2. filter entries by their + idle-time, given in milliseconds (optional). """ + if {min, max, count} == {None}: + if idle is not None or consumername is not None: + raise DataError("if XPENDING is provided with idle time" + " or consumername, it must be provided" + " with min, max and count parameters") + return self.xpending(name, groupname) + pieces = [name, groupname] - if min is not None or max is not None or count is not None: - if min is None or max is None or count is None: - raise DataError("XPENDING must be provided with min, max " - "and count parameters, or none of them. ") - if not isinstance(count, int) or count < -1: - raise DataError("XPENDING count must be a integer >= -1") - pieces.extend((min, max, str(count))) - if consumername is not None: - if min is None or max is None or count is None: - raise DataError("if XPENDING is provided with consumername," - " it must be provided with min, max and" - " count parameters") - pieces.append(consumername) + if min is None or max is None or count is None: + raise DataError("XPENDING must be provided with min, max " + "and count parameters, or none of them.") + # idle + try: + if int(idle) < 0: + raise DataError("XPENDING idle must be a integer >= 0") + pieces.extend(['IDLE', idle]) + except TypeError: + pass + # count + try: + if int(count) < 0: + raise DataError("XPENDING count must be a integer >= 0") + pieces.extend([min, max, count]) + except TypeError: + pass + return self.execute_command('XPENDING', *pieces, parse_detail=True) def xrange(self, name, min='-', max='+', count=None): |