From 1dfda00588bc02ea37b76e4465111c91dd79635e Mon Sep 17 00:00:00 2001 From: Roey Prat Date: Mon, 29 Oct 2018 11:32:34 +0200 Subject: XCLAIM simplify argument checks --- redis/client.py | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'redis/client.py') diff --git a/redis/client.py b/redis/client.py index 2b39c2d..762b3a5 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2013,25 +2013,28 @@ class StrictRedis(object): pieces = [name, groupname, consumername, str(min_idle_time)] pieces.extend(list(message_ids)) - optional_ints = {idle: 'idle', time: 'time', retrycount: 'retrycount'} - optional_ints = {k: Token.get_token(v) for k, v in - optional_ints.items()} - for param_value, param_name in optional_ints.items(): - if param_value is not None: - if not isinstance(param_value, (int, long)): - raise RedisError("XCLAIM {0} must be an integer" - .format(param_name)) - pieces.extend((param_name, str(param_value))) - - optional_bools = {force: 'force', justid: 'justid'} - optional_bools = {k: Token.get_token(v) for k, v in - optional_bools.items()} - for param_value, param_name in optional_bools.items(): - if param_value: - if not isinstance(param_value, bool): - raise RedisError("XCLAIM {0} must be a boolean" - .format(param_name)) - pieces.append(param_name.upper()) + if idle is not None: + if not isinstance(idle, (int, long)): + raise RedisError("XCLAIM idle must be an integer") + pieces.extend((Token.get_token('IDLE'), str(idle))) + if time is not None: + if not isinstance(time, (int, long)): + raise RedisError("XCLAIM time must be an integer") + pieces.extend((Token.get_token('TIME'), str(time))) + if retrycount is not None: + if not isinstance(retrycount, (int, long)): + raise RedisError("XCLAIM retrycount must be an integer") + pieces.extend((Token.get_token('RETRYCOUNT'), str(retrycount))) + + if force: + if not isinstance(force, bool): + raise RedisError("XCLAIM force must be a boolean") + pieces.append(Token.get_token('FORCE')) + if justid: + if not isinstance(justid, bool): + raise RedisError("XCLAIM justid must be a boolean") + pieces.append(Token.get_token('JUSTID')) + return self.execute_command('XCLAIM', *pieces) # SORTED SET COMMANDS -- cgit v1.2.1