pub struct RedisList { /* private fields */ }Expand description
Describes one list subscription against a ConnectedRedisBroker.
§Examples
use std::time::Duration;
use ruststream_fred::list::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Job {
id: u64,
}
// Reliable: the entry waits on a processing list until the handler acknowledges it.
#[subscriber(RedisList::new("jobs").reliable().block(Duration::from_secs(2)))]
async fn run_job(job: &Job) -> HandlerOutcome {
tracing::info!(job.id, "running");
HandlerOutcome::ack()
}
// Simple: popped and gone, so a crash mid-handler loses the entry.
#[subscriber(RedisList::new("metrics"))]
async fn record(job: &Job) -> HandlerOutcome {
tracing::info!(job.id, "recorded");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("jobs", "0.1.0")).with_broker(
RedisBroker::standalone("redis://localhost:6379"),
|b| {
b.include(run_job);
b.include(record);
},
)
}Implementations§
Source§impl RedisList
impl RedisList
Sourcepub fn new(key: impl Into<String>) -> Self
pub fn new(key: impl Into<String>) -> Self
A simple (at-most-once) BRPOP work-queue consumer on key.
Sourcepub const fn reliable(self) -> Self
pub const fn reliable(self) -> Self
Switches to reliable (at-least-once) mode: entries move to a processing list and are removed
on ack.
Sourcepub fn processing(self, key: impl Into<String>) -> Self
pub fn processing(self, key: impl Into<String>) -> Self
Sets the processing-list key used in reliable mode. Defaults to <key>.processing.
Sourcepub const fn block(self, block: Duration) -> Self
pub const fn block(self, block: Duration) -> Self
How long one blocking pop waits before looping. Defaults to 5 seconds.
Also reachable at the mount site, after the batch size, through
RedisSubscribeExt.
Sourcepub fn codec(self, codec: impl Codec + 'static) -> Self
pub fn codec(self, codec: impl Codec + 'static) -> Self
Decodes the header/payload envelope with codec (must match the publisher). Without it the
default binary framing is used. Either way the payload arrives as it was published.
Sourcepub const fn min_idle(self, min_idle: Duration) -> Self
pub const fn min_idle(self, min_idle: Duration) -> Self
How long a claimed reliable-mode entry may sit idle on the processing list before the
recovery watchdog returns it to the main list. Required for (and only meaningful with)
recovery_zset.
It has no default and must exceed the longest legitimate handler runtime: set it too low and a healthy consumer’s in-flight entry gets recovered and processed twice.
Sourcepub fn recovery_zset(self, key: impl Into<String>) -> Self
pub fn recovery_zset(self, key: impl Into<String>) -> Self
Opts reliable mode into orphan recovery, naming the ZSET key that tracks in-flight claims.
Off by default (a dead consumer’s entry stays stranded on the processing list). The key has
no sane default, so it is named explicitly here; pair it with min_idle,
which is required when recovery is on. Reliable mode is implied. The
Recovery
page shows the watchdog in a service.
§Examples
use std::time::Duration;
use ruststream_fred::list::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Job {
id: u64,
}
// At-least-once, with the watchdog that returns a dead consumer's entry to the queue. Set
// `min_idle` above the longest handler runtime, or a running job is recovered and repeated.
#[subscriber(
RedisList::new("jobs")
.reliable()
.min_idle(Duration::from_secs(30))
.recovery_zset("jobs.inflight")
)]
async fn run_job(job: &Job) -> HandlerOutcome {
tracing::info!(job.id, "running");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("jobs", "0.1.0")).with_broker(
RedisBroker::standalone("redis://localhost:6379"),
|b| {
b.include(run_job);
},
)
}Sourcepub const fn recovery_ttl(self, ttl: Duration) -> Self
pub const fn recovery_ttl(self, ttl: Duration) -> Self
An optional auto-cleanup TTL on the recovery ZSET key (refreshed on every claim).
When set it must exceed min_idle (and the longest legitimate handler
runtime), or in-flight tracking is dropped before the watchdog can act.
Trait Implementations§
Source§impl IntoSource for RedisList
impl IntoSource for RedisList
Source§impl RedeliveryAddressed<ConnectedRedisBroker> for RedisList
The list key: the subscription pops from it and RedisListPublish pushes onto it, so a
deferred copy lands in the same queue the delivery came from.
impl RedeliveryAddressed<ConnectedRedisBroker> for RedisList
The list key: the subscription pops from it and RedisListPublish pushes onto it, so a
deferred copy lands in the same queue the delivery came from.
Source§fn redelivery_address(
&self,
_connected: &ConnectedRedisBroker,
) -> impl Future<Output = Result<RedeliveryAddress, RedisError>>
fn redelivery_address( &self, _connected: &ConnectedRedisBroker, ) -> impl Future<Output = Result<RedeliveryAddress, RedisError>>
Source§impl SubscriptionSource<ConnectedRedisBroker> for RedisList
impl SubscriptionSource<ConnectedRedisBroker> for RedisList
Source§type Copies = AddressedCopies
type Copies = AddressedCopies
A retry copy is an LPUSH this process makes, and the list key is where it goes.
Source§type Subscriber = RedisListSubscriber
type Subscriber = RedisListSubscriber
Source§fn declare_retry(self, declaration: &RetryDeclaration) -> Self
fn declare_retry(self, declaration: &RetryDeclaration) -> Self
Source§async fn subscribe(
self,
connected: &ConnectedRedisBroker,
) -> Result<Self::Subscriber, RedisError>
async fn subscribe( self, connected: &ConnectedRedisBroker, ) -> Result<Self::Subscriber, RedisError>
Source§fn channel_bindings(&self) -> Bindings
fn channel_bindings(&self) -> Bindings
AsyncAPI document. Read moreSource§fn declare_retry_on(
&self,
connected: &C,
declaration: &RetryDeclaration,
) -> Result<(), DeclareRetryError>
fn declare_retry_on( &self, connected: &C, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>
Source§fn operation_bindings(&self) -> Bindings
fn operation_bindings(&self) -> Bindings
receive operation in the document. Read moreSource§fn message_bindings(&self) -> Bindings
fn message_bindings(&self) -> Bindings
Auto Trait Implementations§
impl !RefUnwindSafe for RedisList
impl !UnwindSafe for RedisList
impl Freeze for RedisList
impl Send for RedisList
impl Sync for RedisList
impl Unpin for RedisList
impl UnsafeUnpin for RedisList
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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