Repository: redis/redis-py
File: redis/cluster.py (Python)

Code before:
                        redis_node.parse_response,
                        redis_node.connection_pool,
                        connection,
                    )
                nodes[node_name].append(c)

            # send the commands in sequence.
            # we  write to all the open sockets for each node first,
            # before reading anything
            # this allows us to flush all the requests out across the
            # network
            # so that we can read them from different sockets as they come back.
            # we dont' multiplex on the sockets as they come available,
            # but that shouldn't make too much difference.
            node_commands = nodes.values()
            for n in node_commands:
                nodes_written += 1
                n.write()

            for n in node_commands:
                n.read()
                nodes_read += 1
        finally:
            # release all the redis connections we allocated earlier
            # back into the connection pool.
            # if we the connection is dirty (that is: we've written
            # commands to it, but haven't read the responses), we need
            # to close the connection before returning it to the pool.
            # otherwise, the next caller to use this connection will
            # read the response from _this_ request, not its own request.
            # disconnecting discards the dirty state & forces the next
            # caller to reconnect.
            # NOTE: dicts have a consistent ordering; we're iterating
            # through nodes.values() in the same order as we are when
            # reading / writing to the connections above, which is critical
            # for how we're using the nodes_written/nodes_read offsets.
            for i, n in enumerate(nodes.values()):
                if i < nodes_written and i >= nodes_read:
                    n.connection.disconnect()
                n.connection_pool.release(n.connection)

        # if the response isn't an exception it is a
        # valid response from the node
        # we're all done with that command, YAY!
        # if we have more commands to attempt, we've run into problems.
        # collect all the commands we are allowed to retry.
        # (MOVED, ASK, or connection errors or timeout errors)
        attempt = sorted(
            (
                c
                for c in attempt

Review comment (suggestion):
Grammar error in comment: 'if we the connection' should be 'if the connection'.
```suggestion
            # if the connection is dirty (that is: we've written
```

Code after:
            RequestPolicy.ALL_REPLICAS: self.get_replicas,
            RequestPolicy.MULTI_SHARD: lambda *args,
            **kwargs: self._split_multi_shard_command(*args, **kwargs),
            RequestPolicy.SPECIAL: self.get_special_nodes,
            ResponsePolicy.DEFAULT_KEYLESS: lambda res: res,
            ResponsePolicy.DEFAULT_KEYED: lambda res: res,
        }

        self._policy_resolver = policy_resolver

        if event_dispatcher is None:
            self._event_dispatcher = EventDispatcher()
        else:
            self._event_dispatcher = event_dispatcher

    def __repr__(self):
        """ """
        return f"{type(self).__name__}"

    def __enter__(self):
        """ """
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        """ """
        self.reset()

    def __del__(self):
        try:
            self.reset()
        except Exception:
            pass

    def __len__(self):
        """ """
        return len(self._execution_strategy.command_queue)

    def __bool__(self):
        "Pipeline instances should  always evaluate to True on Python 3+"
        return True

    def execute_command(self, *args, **kwargs):
        """
        Wrapper function for pipeline_execute_command
        """
        return self._execution_strategy.execute_command(*args, **kwargs)

    def pipeline_execute_command(self, *args, **options):
        """
        Stage a command to be executed when execute() is next called