How to use the iredis.config.config.withscores function in iredis

To help you get started, we’ve selected a few iredis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github laixintao / iredis / tests / test_render_functions.py View on Github external
def test_render_members(completer):
    completer.completers["members"].words = []
    config.raw = False
    config.withscores = True
    rendered = renders.render_members([b"duck", b"667", b"camel", b"708"], completer)

    assert rendered == FormattedText(
        [
            ("", "1)"),
            ("", " "),
            ("class:integer", "667 "),
            ("class:member", '"duck"'),
            ("", "\n"),
            ("", "2)"),
            ("", " "),
            ("class:integer", "708 "),
            ("class:member", '"camel"'),
        ]
    )
    assert completer.completers["member"].words == ["camel", "duck"]
github laixintao / iredis / iredis / client.py View on Github external
redis_resp = self.execute_command_and_read_response(
                completer, command_name, *args
            )
            self.after_hook(raw_command, command_name, args, completer)
            if command_name.upper() == "MONITOR":
                logger.info("monitor")
                print_formatted_text(redis_resp, style=STYLE)
                try:
                    self.monitor()
                except KeyboardInterrupt:
                    return
        except Exception as e:
            logger.exception(e)
            return render_error(str(e))
        finally:
            config.withscores = False
        return redis_resp
github laixintao / iredis / iredis / renders.py View on Github external
def render_members(items, completer):
    if config.withscores:
        if config.raw:
            return _update_completer_then_render(
                items, completer, "member", "class:member", completer_iter_step=2
            )
        return _update_completer_then_render_withscores(items, completer)
    return _update_completer_then_render(
        items, completer, "member", "class:member", completer_iter_step=1
    )
github laixintao / iredis / iredis / client.py View on Github external
def pre_hook(self, command, command_name, args, completer):
        """
        Before execute command, patch completers first.
        Eg: When user run `GET foo`, key completer need to
          touch foo.

        Only works when compile-grammar thread is done.
        """
        # TRANSATION state chage
        if command_name.upper() in ["EXEC", "DISCARD"]:
            logger.debug(f"[After hook] Command is {command_name}, unset transaction.")
            config.transaction = False
        # score display for sorted set
        if command_name.upper() in ["ZSCAN", "ZPOPMAX", "ZPOPMIN"]:
            config.withscores = True

        # patch completers
        if not completer:
            logger.warning("[Pre patch completer] Complter not ready, not patched...")
            return
        redis_grammar = completer.compiled_grammar
        m = redis_grammar.match(command)
        if not m:
            # invalide command!
            return
        variables = m.variables()
        # zset withscores
        withscores = variables.get("withscores")
        logger.debug(f"[PRE HOOK] withscores: {withscores}")
        if withscores:
            config.withscores = True