pub struct RedisTransaction { /* private fields */ }Expand description
An owned Redis transaction, opened by transaction on a
RedisPublisher.
A private XADD buffer, flushed on commit through the same MULTI / EXEC path as the
handle-level kind (so the whole batch becomes visible atomically, in publish order) and
discarded on abort.
What sets it apart from the handle-level TransactionalPublisher buffer is ownership, not
the commit: any number of these can be open on one handle at a time, and the handle keeps
publishing directly while they are. The buffers are independent, so settling one never touches
another; only the flush itself takes a pooled connection.
§Examples
use ruststream::{Broker, OutgoingMessage, OwnedTransactions, Transaction};
use ruststream_fred::RedisBroker;
let connected = RedisBroker::standalone("redis://localhost:6379").connect().await?;
let publisher = connected.publisher();
let mut orders = publisher.transaction().await?;
let mut audit = publisher.transaction().await?; // concurrent with `orders`
orders.publish(OutgoingMessage::new("orders", b"{}".as_slice())).await?;
audit.publish(OutgoingMessage::new("audit", b"{}".as_slice())).await?;
orders.commit().await?;
audit.commit().await?;Trait Implementations§
Source§impl Debug for RedisTransaction
impl Debug for RedisTransaction
Source§impl Drop for RedisTransaction
impl Drop for RedisTransaction
Source§impl Transaction for RedisTransaction
impl Transaction for RedisTransaction
Source§async fn publish(&mut self, msg: OutgoingMessage<'_>) -> Result<(), Self::Error>
async fn publish(&mut self, msg: OutgoingMessage<'_>) -> Result<(), Self::Error>
Buffers the XADD locally; nothing reaches the server before commit.
Source§async fn commit(self) -> Result<(), Self::Error>
async fn commit(self) -> Result<(), Self::Error>
Flushes the buffer as one MULTI / EXEC block, in publish order.
§Errors
Returns RedisError::ShutDown when the connection this transaction was opened from is
gone, or RedisError::Publish when the block is rejected. A failed commit has still
consumed the transaction and its buffer is lost; redelivery of the inputs, not
resubmission of the buffer, is the recovery path.
Source§async fn abort(self) -> Result<(), Self::Error>
async fn abort(self) -> Result<(), Self::Error>
Discards the buffer. Nothing was sent to the server, so this cannot fail.
Source§type Error = RedisError
type Error = RedisError
Auto Trait Implementations§
impl !RefUnwindSafe for RedisTransaction
impl !UnwindSafe for RedisTransaction
impl Freeze for RedisTransaction
impl Send for RedisTransaction
impl Sync for RedisTransaction
impl Unpin for RedisTransaction
impl UnsafeUnpin for RedisTransaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more