pub struct Transaction<'a> { /* private fields */ }Expand description
One in-flight MULTI block over a Remote connection.
Drop without calling Self::exec / Self::exec_watched /
Self::discard sends an implicit DISCARD so the underlying
socket isn’t left in MULTI mode.
Implementations§
Source§impl<'a> Transaction<'a>
impl<'a> Transaction<'a>
Sourcepub fn queue(&mut self, parts: &[&[u8]]) -> Result<()>
pub fn queue(&mut self, parts: &[&[u8]]) -> Result<()>
Queue one command — verb + args as raw byte slices. The server
replies +QUEUED synchronously; errors propagate as io::Error.
Sourcepub fn exec(self) -> Result<Vec<Reply>>
pub fn exec(self) -> Result<Vec<Reply>>
EXEC — send EXEC, return the per-queued-command reply array.
Consumes the transaction handle.
When a WATCH violation aborts the transaction the server
returns Nil; this method collapses that into an empty Vec
for backward compatibility with v1.4.x. For new code, prefer
exec_watched, which distinguishes
“aborted by WATCH” (returns None) from “successful empty
transaction” (returns Some(vec![])).
Sourcepub fn exec_watched(self) -> Result<Option<Vec<Reply>>>
pub fn exec_watched(self) -> Result<Option<Vec<Reply>>>
Like exec but returns None when a WATCH
violation aborts the transaction (RESP Nil reply to EXEC).
Use this when you’ve called Connection::watch and need to
distinguish an abort from a successfully-empty queue.
Sourcepub fn exec_typed(self) -> Result<TransactionReplies>
pub fn exec_typed(self) -> Result<TransactionReplies>
Like exec but returns a TransactionReplies
cursor with typed extractors (next_int, next_bulk, …) so
callers don’t hand-match every Reply themselves. Aborts with
io::ErrorKind::InvalidData (“transaction aborted by WATCH”) if
the server replied Nil; use exec_watched_typed
to distinguish abort from successfully-empty.
Consumes the handle. The cursor remembers how many replies are
left (TransactionReplies::remaining) so callers can sanity-
check arity at the end of the read sequence.
Sourcepub fn exec_watched_typed(self) -> Result<Option<TransactionReplies>>
pub fn exec_watched_typed(self) -> Result<Option<TransactionReplies>>
Like exec_watched but returns a typed
TransactionReplies cursor on commit; None on WATCH abort.