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 Transaction<'_>
impl Transaction<'_>
Sourcepub fn queue(&mut self, parts: &[&[u8]]) -> KevyResult<()>
pub fn queue(&mut self, parts: &[&[u8]]) -> KevyResult<()>
Queue one command — verb + args as raw byte slices. The server
replies +QUEUED synchronously; errors propagate as io::Error.
Sourcepub fn exec(self) -> KevyResult<Vec<Reply>>
pub fn exec(self) -> KevyResult<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
(legacy behaviour, retained for compat). 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) -> KevyResult<Option<Vec<Reply>>>
pub fn exec_watched(self) -> KevyResult<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) -> KevyResult<TransactionReplies>
pub fn exec_typed(self) -> KevyResult<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) -> KevyResult<Option<TransactionReplies>>
pub fn exec_watched_typed(self) -> KevyResult<Option<TransactionReplies>>
Like exec_watched but returns a typed
TransactionReplies cursor on commit; None on WATCH abort.
Sourcepub fn discard(self) -> KevyResult<()>
pub fn discard(self) -> KevyResult<()>
DISCARD — abandon the queued commands. Consumes the handle.
Source§impl Transaction<'_>
impl Transaction<'_>
Sourcepub fn set(&mut self, key: &[u8], value: &[u8]) -> KevyResult<&mut Self>
pub fn set(&mut self, key: &[u8], value: &[u8]) -> KevyResult<&mut Self>
Queue SET key value.
Sourcepub fn get(&mut self, key: &[u8]) -> KevyResult<&mut Self>
pub fn get(&mut self, key: &[u8]) -> KevyResult<&mut Self>
Queue GET key.
Sourcepub fn del(&mut self, keys: &[&[u8]]) -> KevyResult<&mut Self>
pub fn del(&mut self, keys: &[&[u8]]) -> KevyResult<&mut Self>
Queue DEL key [key ...].
Sourcepub fn exists(&mut self, keys: &[&[u8]]) -> KevyResult<&mut Self>
pub fn exists(&mut self, keys: &[&[u8]]) -> KevyResult<&mut Self>
Queue EXISTS key [key ...].
Sourcepub fn incr(&mut self, key: &[u8]) -> KevyResult<&mut Self>
pub fn incr(&mut self, key: &[u8]) -> KevyResult<&mut Self>
Queue INCR key.
Sourcepub fn incr_by(&mut self, key: &[u8], delta: i64) -> KevyResult<&mut Self>
pub fn incr_by(&mut self, key: &[u8], delta: i64) -> KevyResult<&mut Self>
Queue INCRBY key delta.
Sourcepub fn mget(&mut self, keys: &[&[u8]]) -> KevyResult<&mut Self>
pub fn mget(&mut self, keys: &[&[u8]]) -> KevyResult<&mut Self>
Queue MGET key [key ...].
Sourcepub fn mset(&mut self, pairs: &[(&[u8], &[u8])]) -> KevyResult<&mut Self>
pub fn mset(&mut self, pairs: &[(&[u8], &[u8])]) -> KevyResult<&mut Self>
Queue MSET key value [key value ...].