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

Code before:
        """
        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 bool(reduce(lambda x, y: x and y, 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):
        """
        Asks sentinel servers for the Redis master's address corresponding
        to the service labeled ``service_name``.

Review comment (refactor):
[nitpick] Similar to the sync version, you can use all(responses) instead of reduce to simplify the boolean aggregation.
```suggestion
        return all(responses)
```

Code after:
        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):
        """
        Asks sentinel servers for the Redis master's address corresponding
        to the service labeled ``service_name``.