下面显示的是英文原文。
Lists
RedisList is a work queue: each entry goes to one consumer, and the simple form pops it with BRPOP and settles nothing.
RedisList::new("thumbnails") reads the list thumbnails.
A producer pushes an entry with LPUSH, and a consumer pops it from the other end, so entries arrive in the order they were pushed.
Each entry reaches exactly one consumer: a list has no consumer groups, no fan-out and no replay.
Consumers of one list in several processes share its entries.
The simple form pops the entry with BRPOP, which removes it from Redis.
A handler that crashes after the pop loses the entry, so delivery is at most once.
The outcome settles nothing: an ack, a retry and a drop all report AckError::Unsupported, and the runtime logs a warning for each.
A list that has to keep an entry until its handler finishes uses the reliable form.
How long one pop waits on the server is the subscription's block setting, five seconds by default.
Example
Thumbnails are cheap to make again, so a lost job costs nothing.
- Macros
- Manual
/// Each entry of `thumbnails` reaches one consumer. It left Redis when it was popped, so the
/// outcome settles nothing.
#[subscriber(RedisList::new("thumbnails"))]
async fn make_thumbnail(job: &Job) -> HandlerOutcome {
tracing::info!(job.id, "thumbnail made");
HandlerOutcome::ack()
}
/// Each entry of `thumbnails` reaches one consumer. It left Redis when it was popped, so the
/// outcome settles nothing.
struct MakeThumbnail;
impl Handle<Job, (), (), (), AppState> for MakeThumbnail {
fn handle(
&self,
job: &Job,
_outs: &(),
_ctx: &mut Context<'_, (), AppState>,
) -> impl Future<Output = Result<(), HandlerOutcome>> {
tracing::info!(job.id, "thumbnail made");
ready(Ok(()))
}
}
fn thumbnails() -> RedisList {
RedisList::new("thumbnails")
}