From 9c73b9d7564300259a39d24a6d13d7af0960b281 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Thu, 14 Oct 2021 17:43:28 +0200 Subject: [PATCH 1/2] Support auth2 in MIGRATE --- redis/commands.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/redis/commands.py b/redis/commands.py index baf5239ae4..b6bca67e8c 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -320,7 +320,7 @@ def client_kill_filter(self, _id=None, _type=None, addr=None, client_types = ('normal', 'master', 'slave', 'pubsub') if str(_type).lower() not in client_types: raise DataError("CLIENT KILL type must be one of %r" % ( - client_types,)) + client_types,)) args.extend((b'TYPE', _type)) if skipme is not None: if not isinstance(skipme, bool): @@ -363,7 +363,7 @@ def client_list(self, _type=None, client_id=[]): client_types = ('normal', 'master', 'replica', 'pubsub') if str(_type).lower() not in client_types: raise DataError("CLIENT LIST _type must be one of %r" % ( - client_types,)) + client_types,)) args.append(b'TYPE') args.append(_type) if not isinstance(client_id, list): @@ -542,7 +542,8 @@ def lolwut(self, *version_numbers): return self.execute_command('LOLWUT') def migrate(self, host, port, keys, destination_db, timeout, - copy=False, replace=False, auth=None): + copy=False, replace=False, auth=None, auth2username=None, + auth2Password=None): """ Migrate 1 or more keys from the current Redis server to a different server specified by the ``host``, ``port`` and ``destination_db``. @@ -563,15 +564,20 @@ def migrate(self, host, port, keys, destination_db, timeout, keys = list_or_args(keys, []) if not keys: raise DataError('MIGRATE requires at least one key') + if auth2username is None and auth2Password is not None or \ + auth2Password is None and auth2username is not None: + raise DataError('auth2username and auth2Password must be given together.') pieces = [] if copy: - pieces.append(b'COPY') + pieces.append('COPY') if replace: - pieces.append(b'REPLACE') + pieces.append('REPLACE') if auth: - pieces.append(b'AUTH') + pieces.append('AUTH') pieces.append(auth) - pieces.append(b'KEYS') + if auth2username and auth2Password: + pieces.extend(['AUTH2', auth2username, auth2Password]) + pieces.append('KEYS') pieces.extend(keys) return self.execute_command('MIGRATE', host, port, '', destination_db, timeout, *pieces) @@ -809,6 +815,7 @@ def dump(self, name): def exists(self, *names): "Returns the number of ``names`` that exist" return self.execute_command('EXISTS', *names) + __contains__ = exists def expire(self, name, time): @@ -2992,7 +2999,7 @@ def _georadiusgeneric(self, command, *args, **kwargs): elif kwargs['unit']: pieces.append(kwargs['unit']) else: - pieces.append('m',) + pieces.append('m', ) if kwargs['any'] and kwargs['count'] is None: raise DataError("``any`` can't be provided without ``count``") @@ -3231,6 +3238,7 @@ class BitFieldOperation: """ Command builder for BITFIELD commands. """ + def __init__(self, client, key, default_overflow=None): self.client = client self.key = key From 5640e6dc0bc26f9380b6c9aa7b37f4d333bb182d Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Fri, 15 Oct 2021 09:33:48 +0200 Subject: [PATCH 2/2] flake8 --- redis/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/redis/commands.py b/redis/commands.py index b6bca67e8c..be1895e82b 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -566,7 +566,8 @@ def migrate(self, host, port, keys, destination_db, timeout, raise DataError('MIGRATE requires at least one key') if auth2username is None and auth2Password is not None or \ auth2Password is None and auth2username is not None: - raise DataError('auth2username and auth2Password must be given together.') + raise DataError('auth2username and auth2Password must be ' + 'given together.') pieces = [] if copy: pieces.append('COPY')