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::OutgoingMessage;
use ruststream_fred::stream::prelude::*;
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
RedisBroker::standalone("redis://localhost:6379"),
|b| {
b.include(handle);
// Two buffers open at once on one handle; each commits as its own MULTI / EXEC.
b.after_startup(TransactionalPublish, async move |publisher| {
let mut orders = publisher.transaction().await?;
let mut audit = publisher.transaction().await?;
let seed = OutgoingMessage::new("orders", br#"{"id":0}"#.as_slice());
orders.publish(seed, None).await?;
let note = OutgoingMessage::new("audit", br#"{"seeded":1}"#.as_slice());
audit.publish(note, None).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§type Payload = Take
type Payload = Take
The same as RedisPublisher’s: a buffered XADD hands the client the same value.
Source§type Options = RedisPublishOptions
type Options = RedisPublishOptions
The same as RedisPublisher’s: a buffered XADD is the same command, queued, so a
staged message takes a partition key the way a direct one does.
Source§fn publish(
&mut self,
msg: OutgoingMessage<'_, BytesMut>,
options: Option<&Self::Options>,
) -> impl Future<Output = Result<(), Self::Error>>
fn publish( &mut self, msg: OutgoingMessage<'_, BytesMut>, options: Option<&Self::Options>, ) -> impl Future<Output = 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§fn abort(self) -> impl Future<Output = Result<(), Self::Error>>
fn abort(self) -> impl Future<Output = 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