From d71fd6264d58795c50b9350d7c39677b671e0896 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 17 Jul 2021 09:34:48 +0200 Subject: Merging upstream version 1.9.4. Signed-off-by: Daniel Baumann --- iredis/client.py | 59 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'iredis/client.py') diff --git a/iredis/client.py b/iredis/client.py index 61613dc..2c9bda5 100644 --- a/iredis/client.py +++ b/iredis/client.py @@ -62,6 +62,7 @@ class Client: path=None, scheme="redis", username=None, + client_name=None, ): self.host = host self.port = port @@ -69,17 +70,11 @@ class Client: self.path = path # FIXME username is not using... self.username = username + self.client_name = client_name self.scheme = scheme + self.password = password - self.connection = self.create_connection( - host, - port, - db, - password, - path, - scheme, - username, - ) + self.build_connection() # all command upper case self.answer_callbacks = command2callback @@ -101,6 +96,21 @@ class Client: if config.version and re.match(r"([\d\.]+)", config.version): self.auth_compat(config.version) + def build_connection(self): + """ + create a new connection and replace ``self.connection`` + """ + self.connection = self.create_connection( + self.host, + self.port, + self.db, + self.password, + self.path, + self.scheme, + self.username, + client_name=self.client_name, + ) + def create_connection( self, host=None, @@ -110,6 +120,7 @@ class Client: path=None, scheme="redis", username=None, + client_name=None, ): if scheme in ("redis", "rediss"): connection_kwargs = { @@ -118,13 +129,19 @@ class Client: "db": db, "password": password, "socket_keepalive": config.socket_keepalive, + "client_name": client_name, } if scheme == "rediss": connection_class = SSLConnection else: connection_class = Connection else: - connection_kwargs = {"db": db, "password": password, "path": path} + connection_kwargs = { + "db": db, + "password": password, + "path": path, + "client_name": client_name, + } connection_class = UnixDomainSocketConnection if config.decode: @@ -242,6 +259,15 @@ class Client: except redis.exceptions.ExecAbortError: config.transaction = False raise + except KeyboardInterrupt: + logger.warning("received KeyboardInterrupt... rebuild connection...") + connection.disconnect() + connection.connect() + print( + "KeyboardInterrupt received! User canceled reading response!", + file=sys.stderr, + ) + return None else: return response raise last_error @@ -338,7 +364,7 @@ class Client: grammar = completer.get_completer(input_text=rawinput).compiled_grammar matched = grammar.match(rawinput) if not matched: - # invalide command! + # invalid command! return rawinput, None variables = matched.variables() shell_command = variables.get("shellcommand") @@ -397,12 +423,7 @@ class Client: # subcommand's stdout/stderr if shell_command and config.shell: # pass the raw response of redis to shell command - if isinstance(redis_resp, list): - # FIXME not handling nested list, use renders.render_raw - # instead - stdin = b"\n".join(redis_resp) - else: - stdin = redis_resp + stdin = OutputRender.render_raw(redis_resp) run(shell_command, input=stdin, shell=True) return @@ -486,7 +507,7 @@ class Client: redis_grammar = completer.get_completer(command).compiled_grammar m = redis_grammar.match(command) if not m: - # invalide command! + # invalid command! return variables = m.variables() # zset withscores @@ -501,7 +522,7 @@ class Client: doc = read_text(commands_data, f"{command_docs_name}.md") except FileNotFoundError: raise NotRedisCommand( - f"{command_summary_name} is not a valide Redis command." + f"{command_summary_name} is not a valid Redis command." ) rendered_detail = markdown.render(doc) summary_dict = commands_summary[command_summary_name] -- cgit v1.2.3