def execute_command(self, cmd, callbacks, *args, **kwargs): if cmd in ('AUTH', 'SELECT'): super(Pipeline, self).execute_command(cmd, callbacks, *args, **kwargs) elif cmd in PUB_SUB_COMMANDS: raise RequestError( 'Client is not supposed to issue command %s in pipeline' % cmd) self.command_stack.append(CmdLine(cmd, *args, **kwargs))
def execute_command(self, cmd, callbacks, *args, **kwargs): cmd_line = CmdLine(cmd, *args, **kwargs) with execution_context(callbacks) as ctx: if callbacks is None: callbacks = [] elif not hasattr(callbacks, '__iter__'): callbacks = [callbacks] if self.subscribed and cmd not in PUB_SUB_COMMANDS: ctx.ret_call(RequestError('Calling not pub/sub command during subscribed state', cmd_line)) return try: self.connection.write(self.format(cmd, *args)) except Exception as e: self.connection.disconnect() raise e if self.subscribed and cmd in ('SUBSCRIBE', 'UNSUBSCRIBE'): self._waiting_callbacks[cmd].append(callbacks) return yield self.connection.queue_wait() data = yield async(self.connection.readline)() if not data: result = None self.connection.read_done() raise Exception('TODO: [no data from connection->readline') else: response = yield self.process_data(data, cmd_line) result = self.format_reply(cmd_line, response) self.connection.read_done() ctx.ret_call(result)