Repository: redis/redis-py
File: redis/asyncio/sentinel.py (Python)

Code before:
    async def execute_command(self, *args, **kwargs):
        """
        Execute Sentinel command in sentinel nodes.
        once - If set to True, then execute the resulting command on a single
               node at random, rather than across the entire sentinel cluster.
        """
        kwargs.pop("keys", None)  # the keys are used only for client side caching
        once = bool(kwargs.get("once", False))
        if "once" in kwargs.keys():
            kwargs.pop("once")

        # Check if command suppose to return boolean response.
        bool_resp = bool(kwargs.get("bool_resp", False))
        if "bool_resp" in kwargs.keys():
            kwargs.pop("bool_resp")

        if once:
            return await random.choice(self.sentinels).execute_command(*args, **kwargs)

        tasks = [
            asyncio.Task(sentinel.execute_command(*args, **kwargs))
            for sentinel in self.sentinels
        ]
        responses = await asyncio.gather(*tasks)

        if bool_resp:
            return reduce(lambda x, y: x and y, responses)

        return responses

    def __repr__(self):
        sentinel_addresses = []
        for sentinel in self.sentinels:
            sentinel_addresses.append(
                f"{sentinel.connection_pool.connection_kwargs['host']}:"
                f"{sentinel.connection_pool.connection_kwargs['port']}"
            )
        return (
            f"<{self.__class__}.{self.__class__.__name__}"
            f"(sentinels=[{','.join(sentinel_addresses)}])>"
        )

    def check_master_state(self, state: dict, service_name: str) -> bool:
        if not state["is_master"] or state["is_sdown"] or state["is_odown"]:
            return False
        # Check if our sentinel doesn't see other nodes
        if state["num-other-sentinels"] < self.min_other_sentinels:
            return False
        return True

    async def discover_master(self, service_name: str):

Review comment (suggestion):
I think we need to change the behaviour here to be backward compatible. The default behaviour should be still "return True", if you want to return the actual responses you have to explicitly specify this.

So instead we would likely to have something like `return_responses=True` flag and we will return actual response if it will be explicitly set.



Code after:
        once - If set to True, then execute the resulting command on a single
               node at random, rather than across the entire sentinel cluster.
        """
        once = bool(kwargs.pop("once", False))

        # Check if command is supposed to return the original
        # responses instead of boolean value.
        return_responses = bool(kwargs.pop("return_responses", False))

        if once:
            response = await random.choice(self.sentinels).execute_command(
                *args, **kwargs
            )
            if return_responses:
                return [response]
            else:
                return True if response else False

        tasks = [
            asyncio.Task(sentinel.execute_command(*args, **kwargs))
            for sentinel in self.sentinels
        ]
        responses = await asyncio.gather(*tasks)

        if return_responses:
            return responses

        return all(responses)

    def __repr__(self):
        sentinel_addresses = []
        for sentinel in self.sentinels:
            sentinel_addresses.append(
                f"{sentinel.connection_pool.connection_kwargs['host']}:"
                f"{sentinel.connection_pool.connection_kwargs['port']}"
            )
        return (
            f"<{self.__class__}.{self.__class__.__name__}"
            f"(sentinels=[{','.join(sentinel_addresses)}])>"
        )

    def check_master_state(self, state: dict, service_name: str) -> bool:
        if not state["is_master"] or state["is_sdown"] or state["is_odown"]:
            return False
        # Check if our sentinel doesn't see other nodes
        if state["num-other-sentinels"] < self.min_other_sentinels:
            return False
        return True

    async def discover_master(self, service_name: str):
        """