MCPcopy
hub / github.com/redis/redis-py / _execute_transaction

Method _execute_transaction

redis/client.py:1879–1949  ·  view source on GitHub ↗
(
        self, connection: Connection, commands, raise_on_error
    )

Source from the content-addressed store, hash-verified

1877 return self
1878
1879 def _execute_transaction(
1880 self, connection: Connection, commands, raise_on_error
1881 ) -> List:
1882 cmds = chain([(("MULTI",), {})], commands, [(("EXEC",), {})])
1883 all_cmds = connection.pack_commands(
1884 [args for args, options in cmds if EMPTY_RESPONSE not in options]
1885 )
1886 connection.send_packed_command(all_cmds)
1887 errors = []
1888
1889 # parse off the response for MULTI
1890 # NOTE: we need to handle ResponseErrors here and continue
1891 # so that we read all the additional command messages from
1892 # the socket
1893 try:
1894 self.parse_response(connection, "_")
1895 except ResponseError as e:
1896 errors.append((0, e))
1897
1898 # and all the other commands
1899 for i, command in enumerate(commands):
1900 if EMPTY_RESPONSE in command[1]:
1901 errors.append((i, command[1][EMPTY_RESPONSE]))
1902 else:
1903 try:
1904 self.parse_response(connection, "_")
1905 except ResponseError as e:
1906 self.annotate_exception(e, i + 1, command[0])
1907 errors.append((i, e))
1908
1909 # parse the EXEC.
1910 try:
1911 response = self.parse_response(connection, "_")
1912 except ExecAbortError:
1913 if errors:
1914 raise errors[0][1]
1915 raise
1916
1917 # EXEC clears any watched keys
1918 self.watching = False
1919
1920 if response is None:
1921 raise WatchError("Watched variable changed.")
1922
1923 # put any parse errors into the response
1924 for i, e in errors:
1925 response.insert(i, e)
1926
1927 if len(response) != len(commands):
1928 self.connection.disconnect()
1929 raise ResponseError(
1930 "Wrong number of response items from pipeline execution"
1931 )
1932
1933 # find any errors in the response and raise if necessary
1934 if raise_on_error:
1935 self.raise_first_error(commands, response)
1936

Callers

nothing calls this directly

Calls 10

parse_responseMethod · 0.95
annotate_exceptionMethod · 0.95
raise_first_errorMethod · 0.95
WatchErrorClass · 0.90
ResponseErrorClass · 0.90
pack_commandsMethod · 0.45
send_packed_commandMethod · 0.45
appendMethod · 0.45
insertMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected