Skip to main content

RedisList

Struct RedisList 

Source
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

Source

pub fn new(key: impl Into<String>) -> Self

A simple (at-most-once) BRPOP work-queue consumer on key.

Source

pub const fn reliable(self) -> Self

Switches to reliable (at-least-once) mode: entries move to a processing list and are removed on ack.

Source

pub fn processing(self, key: impl Into<String>) -> Self

Sets the processing-list key used in reliable mode. Defaults to <key>.processing.

Source

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.

Source

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.

Source

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.

Source

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);
        },
    )
}
Source

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.

Source

pub fn key(&self) -> &str

The list key this subscription consumes.

Trait Implementations§

Source§

impl Clone for RedisList

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RedisList

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoSource for RedisList

Source§

type Source = RedisList

The source the constructor stores.
Source§

fn into_source(self) -> Self

Builds the source.
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.

Source§

fn redelivery_address( &self, _connected: &ConnectedRedisBroker, ) -> impl Future<Output = Result<RedeliveryAddress, RedisError>>

Where a publish reaches this subscription again. Read more
Source§

impl SubscriptionSource<ConnectedRedisBroker> for RedisList

Source§

type Copies = AddressedCopies

A retry copy is an LPUSH this process makes, and the list key is where it goes.

Source§

type Subscriber = RedisListSubscriber

The subscriber type this source opens.
Source§

fn name(&self) -> &str

The name (subject / channel) this subscription binds to. Read more
Source§

fn declare_retry(self, declaration: &RetryDeclaration) -> Self

Takes the registration’s retry declaration into the descriptor, before the subscription opens. Read more
Source§

async fn subscribe( self, connected: &ConnectedRedisBroker, ) -> Result<Self::Subscriber, RedisError>

Opens the subscription against the connected broker. Called once at startup. Read more
Source§

fn channel_bindings(&self) -> Bindings

What this subscription adds to its channel in the generated AsyncAPI document. Read more
Source§

fn declare_retry_on( &self, connected: &C, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>

Carries the registration’s declaration to the broker, at the same point and before the subscription opens. Read more
Source§

fn operation_bindings(&self) -> Bindings

What this subscription adds to its receive operation in the document. Read more
Source§

fn message_bindings(&self) -> Bindings

What this subscription adds to the messages that arrive on it. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Descriptor> OpensWindow for Descriptor
where Descriptor: Base,

Source§

type Pipelined = Pipelined<Descriptor>

The same source with a window.
Source§

fn open_window(self) -> <Descriptor as OpensWindow>::Pipelined

Opens the window.
Source§

impl<T> PublishedThrough<DefaultSlot> for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more