legit_streams/streams.rs
1//! The stream commands the crate uses, behind a trait.
2
3use std::fmt;
4use std::time::Duration;
5
6#[cfg(doc)]
7use crate::entry::LostLease;
8use crate::entry::{AutoClaim, Entry, EntryId, GroupBacklog, Pending, Renewal};
9use crate::error::Result;
10
11/// The Redis stream commands this crate sends, and nothing else. [`RedisStreams`](crate::RedisStreams)
12/// sends them to a server; [`MemoryStreams`](crate::MemoryStreams) runs them in memory for tests.
13///
14/// Every method takes `&self` and may be called from many threads at once. Each is one command
15/// with the Redis semantics its name gives, except [`Streams::xack_xdel`] and
16/// [`Streams::xadd_expire`], which send two, and [`Streams::renew_lease`] and
17/// [`Streams::release_lease`], which check an entry's owner and claim it in one atomic step. An
18/// implementation must keep those two atomic: a worker's lease depends on it.
19///
20/// The fast lane's commands, [`Streams::xread`], [`Streams::expire`], [`Streams::del`] and
21/// [`Streams::xadd_expire`], came after the others. An implementation written before them still
22/// compiles: their default answers [`Error::Redis`](crate::Error::Redis) for the first three, so
23/// such an implementation serves the bulk lane only. So did [`Streams::group_backlog`], which no
24/// worker, producer or reader of this crate calls; by default it answers `None`.
25///
26/// ```
27/// use legit_streams::{MemoryStreams, Streams};
28///
29/// let streams = MemoryStreams::new();
30/// streams.xadd("hash_tasks", &[(b"task_id".as_slice(), b"app_1".as_slice())])?;
31/// assert_eq!(streams.xlen("hash_tasks")?, 1);
32/// # Ok::<(), legit_streams::Error>(())
33/// ```
34pub trait Streams: Send + Sync + fmt::Debug {
35 /// `XADD stream * field value ...`: append an entry and return its id.
36 ///
37 /// # Errors
38 ///
39 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
40 ///
41 /// ```
42 /// use legit_streams::{MemoryStreams, Streams};
43 ///
44 /// let streams = MemoryStreams::new();
45 /// let first = streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
46 /// let second = streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
47 /// assert!(first < second);
48 /// # Ok::<(), legit_streams::Error>(())
49 /// ```
50 fn xadd(&self, stream: &str, fields: &[(&[u8], &[u8])]) -> Result<EntryId>;
51
52 /// `XLEN stream`: how many entries the stream holds, 0 when it doesn't exist.
53 ///
54 /// # Errors
55 ///
56 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
57 ///
58 /// ```
59 /// use legit_streams::{MemoryStreams, Streams};
60 ///
61 /// assert_eq!(MemoryStreams::new().xlen("missing")?, 0);
62 /// # Ok::<(), legit_streams::Error>(())
63 /// ```
64 fn xlen(&self, stream: &str) -> Result<u64>;
65
66 /// `XGROUP CREATE stream group 0 MKSTREAM`: create the group, reading from the start of the
67 /// stream, and the stream when it doesn't exist. Returns `false` when the group already
68 /// existed (`BUSYGROUP`), which isn't an error.
69 ///
70 /// # Errors
71 ///
72 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
73 ///
74 /// ```
75 /// use legit_streams::{MemoryStreams, Streams};
76 ///
77 /// let streams = MemoryStreams::new();
78 /// assert!(streams.xgroup_create("s", "g")?);
79 /// assert!(!streams.xgroup_create("s", "g")?);
80 /// # Ok::<(), legit_streams::Error>(())
81 /// ```
82 fn xgroup_create(&self, stream: &str, group: &str) -> Result<bool>;
83
84 /// `XREADGROUP GROUP group consumer COUNT count [BLOCK ms] STREAMS stream >`: deliver up to
85 /// `count` entries no consumer of the group has seen, adding each to the group's pending list
86 /// under `consumer`. With `block`, wait up to that long for one when there are none; `None`
87 /// returns at once. A `block` under a millisecond waits a millisecond: Redis reads `BLOCK 0`
88 /// as forever.
89 ///
90 /// # Errors
91 ///
92 /// [`Error::NoGroup`](crate::Error::NoGroup) when the group doesn't exist, and
93 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
94 ///
95 /// ```
96 /// use legit_streams::{MemoryStreams, Streams};
97 ///
98 /// let streams = MemoryStreams::new();
99 /// streams.xgroup_create("s", "g")?;
100 /// streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
101 /// assert_eq!(streams.xreadgroup("s", "g", "c", 10, None)?.len(), 1);
102 /// assert!(streams.xreadgroup("s", "g", "c", 10, None)?.is_empty());
103 /// # Ok::<(), legit_streams::Error>(())
104 /// ```
105 fn xreadgroup(
106 &self,
107 stream: &str,
108 group: &str,
109 consumer: &str,
110 count: usize,
111 block: Option<Duration>,
112 ) -> Result<Vec<Entry>>;
113
114 /// `XAUTOCLAIM stream group consumer min-idle start COUNT count`: scan the pending list from
115 /// `start` and claim for `consumer` up to `count` entries idle at least `min_idle`, adding one
116 /// to each one's delivery count.
117 ///
118 /// # Errors
119 ///
120 /// [`Error::NoGroup`](crate::Error::NoGroup) when the group doesn't exist, and
121 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
122 ///
123 /// ```
124 /// use std::time::Duration;
125 /// use legit_streams::{EntryId, MemoryStreams, Streams};
126 ///
127 /// let streams = MemoryStreams::new();
128 /// streams.xgroup_create("s", "g")?;
129 /// let claim = streams.xautoclaim("s", "g", "c", Duration::from_secs(60), EntryId::ZERO, 10)?;
130 /// assert!(claim.claimed.is_empty());
131 /// # Ok::<(), legit_streams::Error>(())
132 /// ```
133 fn xautoclaim(
134 &self,
135 stream: &str,
136 group: &str,
137 consumer: &str,
138 min_idle: Duration,
139 start: EntryId,
140 count: usize,
141 ) -> Result<AutoClaim>;
142
143 /// `XCLAIM stream group consumer 0 id ... [IDLE ms] JUSTID`: give pending entries to
144 /// `consumer` without counting a delivery, and return the ids claimed. Without `idle` their
145 /// idle time restarts at 0, which renews a lease; with it, it's set to `idle`, which can make
146 /// an entry claimable by another worker at once. Ids no longer pending are skipped.
147 ///
148 /// # Errors
149 ///
150 /// [`Error::NoGroup`](crate::Error::NoGroup) when the group doesn't exist, and
151 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
152 ///
153 /// ```
154 /// use legit_streams::{EntryId, MemoryStreams, Streams};
155 ///
156 /// let streams = MemoryStreams::new();
157 /// streams.xgroup_create("s", "g")?;
158 /// assert!(streams.xclaim_justid("s", "g", "c", &[EntryId::new(1, 0)], None)?.is_empty());
159 /// # Ok::<(), legit_streams::Error>(())
160 /// ```
161 fn xclaim_justid(
162 &self,
163 stream: &str,
164 group: &str,
165 consumer: &str,
166 ids: &[EntryId],
167 idle: Option<Duration>,
168 ) -> Result<Vec<EntryId>>;
169
170 /// `XPENDING stream group id id 1`: the pending list's record of one entry, or `None` when
171 /// it isn't pending.
172 ///
173 /// # Errors
174 ///
175 /// [`Error::NoGroup`](crate::Error::NoGroup) when the group doesn't exist, and
176 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
177 ///
178 /// ```
179 /// use legit_streams::{MemoryStreams, Streams};
180 ///
181 /// let streams = MemoryStreams::new();
182 /// streams.xgroup_create("s", "g")?;
183 /// let id = streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
184 /// streams.xreadgroup("s", "g", "c", 1, None)?;
185 /// assert_eq!(streams.xpending_entry("s", "g", id)?.map(|p| p.deliveries), Some(1));
186 /// # Ok::<(), legit_streams::Error>(())
187 /// ```
188 fn xpending_entry(&self, stream: &str, group: &str, id: EntryId) -> Result<Option<Pending>>;
189
190 /// `XPENDING stream group - + count consumer`: up to `count` of the entries `consumer` owns,
191 /// oldest first.
192 ///
193 /// # Errors
194 ///
195 /// [`Error::NoGroup`](crate::Error::NoGroup) when the group doesn't exist, and
196 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
197 ///
198 /// ```
199 /// use legit_streams::{MemoryStreams, Streams};
200 ///
201 /// let streams = MemoryStreams::new();
202 /// streams.xgroup_create("s", "g")?;
203 /// assert!(streams.xpending_consumer("s", "g", "c", 10)?.is_empty());
204 /// # Ok::<(), legit_streams::Error>(())
205 /// ```
206 fn xpending_consumer(&self, stream: &str, group: &str, consumer: &str, count: usize) -> Result<Vec<Pending>>;
207
208 /// `XACK stream group id ...`: drop entries from the group's pending list, returning how many
209 /// were pending.
210 ///
211 /// # Errors
212 ///
213 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
214 ///
215 /// ```
216 /// use legit_streams::{EntryId, MemoryStreams, Streams};
217 ///
218 /// assert_eq!(MemoryStreams::new().xack("s", "g", &[EntryId::new(1, 0)])?, 0);
219 /// # Ok::<(), legit_streams::Error>(())
220 /// ```
221 fn xack(&self, stream: &str, group: &str, ids: &[EntryId]) -> Result<u64>;
222
223 /// `XDEL stream id ...`: delete entries from the stream, returning how many existed.
224 ///
225 /// # Errors
226 ///
227 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
228 ///
229 /// ```
230 /// use legit_streams::{MemoryStreams, Streams};
231 ///
232 /// let streams = MemoryStreams::new();
233 /// let id = streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
234 /// assert_eq!(streams.xdel("s", &[id])?, 1);
235 /// assert_eq!(streams.xlen("s")?, 0);
236 /// # Ok::<(), legit_streams::Error>(())
237 /// ```
238 fn xdel(&self, stream: &str, ids: &[EntryId]) -> Result<u64>;
239
240 /// `XACK` then `XDEL`: how the contract finishes with an entry, so streams don't grow.
241 /// [`RedisStreams`](crate::RedisStreams) sends both in one round trip.
242 ///
243 /// # Errors
244 ///
245 /// [`Error::Redis`](crate::Error::Redis) when the server refuses either or can't be reached;
246 /// the acknowledgement may have happened.
247 ///
248 /// ```
249 /// use legit_streams::{MemoryStreams, Streams};
250 ///
251 /// let streams = MemoryStreams::new();
252 /// streams.xgroup_create("s", "g")?;
253 /// streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
254 /// let entries = streams.xreadgroup("s", "g", "c", 1, None)?;
255 /// streams.xack_xdel("s", "g", &[entries[0].id])?;
256 /// assert_eq!(streams.xlen("s")?, 0);
257 /// # Ok::<(), legit_streams::Error>(())
258 /// ```
259 fn xack_xdel(&self, stream: &str, group: &str, ids: &[EntryId]) -> Result<()> {
260 self.xack(stream, group, ids)?;
261 self.xdel(stream, ids)?;
262 Ok(())
263 }
264
265 /// `XGROUP DELCONSUMER stream group consumer`: remove a consumer, and with it any entries it
266 /// still owns; returns how many it owned.
267 ///
268 /// # Errors
269 ///
270 /// [`Error::NoGroup`](crate::Error::NoGroup) when the group doesn't exist, and
271 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
272 ///
273 /// ```
274 /// use legit_streams::{MemoryStreams, Streams};
275 ///
276 /// let streams = MemoryStreams::new();
277 /// streams.xgroup_create("s", "g")?;
278 /// assert_eq!(streams.xgroup_delconsumer("s", "g", "c")?, 0);
279 /// # Ok::<(), legit_streams::Error>(())
280 /// ```
281 fn xgroup_delconsumer(&self, stream: &str, group: &str, consumer: &str) -> Result<u64>;
282
283 /// Renew `consumer`'s lease on a pending entry, as one atomic step on the server: if, at the
284 /// instant it runs, the entry is pending in the group for `consumer`, its idle time becomes 0
285 /// and nothing else changes, neither its owner nor its delivery count; otherwise nothing
286 /// changes and the answer is [`Renewal::Lost`]. An entry still pending but deleted from the
287 /// stream is dropped from the pending list and answers [`LostLease::NotPending`].
288 ///
289 /// The check and the renewal must be one step. A check followed by a separate `XCLAIM` lets
290 /// another worker's `XAUTOCLAIM` land between the two, and the `XCLAIM` then takes the entry
291 /// straight back: two workers run the task, each holding what it believes is the lease.
292 /// [`RedisStreams`](crate::RedisStreams) runs both in one server-side script, which Redis runs
293 /// with no other command in between.
294 ///
295 /// # Errors
296 ///
297 /// [`Error::NoGroup`](crate::Error::NoGroup) when the group doesn't exist, which a worker
298 /// treats as a lost lease, and [`Error::Redis`](crate::Error::Redis) when the server refuses it
299 /// or can't be reached, which says nothing about the lease.
300 ///
301 /// ```
302 /// use legit_streams::{LostLease, MemoryStreams, Renewal, Streams};
303 ///
304 /// let streams = MemoryStreams::new();
305 /// streams.xgroup_create("s", "g")?;
306 /// let id = streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
307 /// streams.xreadgroup("s", "g", "a", 1, None)?;
308 /// assert_eq!(streams.renew_lease("s", "g", "a", id)?, Renewal::Renewed);
309 /// assert_eq!(streams.renew_lease("s", "g", "b", id)?, Renewal::Lost(LostLease::OtherConsumer));
310 /// streams.xack("s", "g", &[id])?;
311 /// assert_eq!(streams.renew_lease("s", "g", "a", id)?, Renewal::Lost(LostLease::NotPending));
312 /// # Ok::<(), legit_streams::Error>(())
313 /// ```
314 fn renew_lease(&self, stream: &str, group: &str, consumer: &str, id: EntryId) -> Result<Renewal>;
315
316 /// Release `consumer`'s lease on a pending entry, as one atomic step on the server: if the
317 /// entry is pending in the group for `consumer`, its idle time is set to `idle`, so a worker
318 /// that claims entries idle that long takes it at once; otherwise nothing changes. The owner
319 /// and the delivery count don't change. Returns whether the entry was released. As with
320 /// [`Streams::renew_lease`], a separate check and `XCLAIM` could take back an entry another
321 /// worker has just claimed.
322 ///
323 /// # Errors
324 ///
325 /// [`Error::NoGroup`](crate::Error::NoGroup) when the group doesn't exist, and
326 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
327 ///
328 /// ```
329 /// use std::time::Duration;
330 /// use legit_streams::{Clock, MemoryStreams, Streams};
331 ///
332 /// let streams = MemoryStreams::with_clock(Clock::manual(1_000_000));
333 /// streams.xgroup_create("s", "g")?;
334 /// let id = streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
335 /// streams.xreadgroup("s", "g", "a", 1, None)?;
336 /// assert!(!streams.release_lease("s", "g", "b", id, Duration::from_secs(300))?);
337 /// assert!(streams.release_lease("s", "g", "a", id, Duration::from_secs(300))?);
338 /// assert_eq!(streams.pending("s", "g")[0].idle, Duration::from_secs(300));
339 /// # Ok::<(), legit_streams::Error>(())
340 /// ```
341 fn release_lease(&self, stream: &str, group: &str, consumer: &str, id: EntryId, idle: Duration) -> Result<bool>;
342
343 /// `XREAD COUNT count [BLOCK ms] STREAMS stream after`: up to `count` entries added after
344 /// `after`, without a consumer group, so nothing is delivered or pending. With `block`, wait
345 /// up to that long for one when there are none; `None` returns at once. A `block` under a
346 /// millisecond waits a millisecond, as for [`Streams::xreadgroup`]. A stream that doesn't
347 /// exist reads as empty. `count` 0 means no limit.
348 ///
349 /// Reading from [`EntryId::ZERO`] gives the entries already there, so a fast-lane caller that
350 /// reads its own reply key from `0` sees a reply that arrived before its read began.
351 ///
352 /// # Errors
353 ///
354 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached, and
355 /// by default, for an implementation that doesn't send it.
356 ///
357 /// ```
358 /// use legit_streams::{EntryId, MemoryStreams, Streams};
359 ///
360 /// let streams = MemoryStreams::new();
361 /// let id = streams.xadd("reply", &[(b"k".as_slice(), b"v".as_slice())])?;
362 /// assert_eq!(streams.xread("reply", EntryId::ZERO, 1, None)?[0].id, id);
363 /// assert!(streams.xread("reply", id, 1, None)?.is_empty());
364 /// # Ok::<(), legit_streams::Error>(())
365 /// ```
366 fn xread(&self, stream: &str, after: EntryId, count: usize, block: Option<Duration>) -> Result<Vec<Entry>> {
367 let _ = (stream, after, count, block);
368 Err(unsupported("XREAD"))
369 }
370
371 /// `EXPIRE key seconds`: delete the key once `ttl` has passed, replacing any expiry it had.
372 /// The time is rounded up to whole seconds, so the key never goes sooner than asked; a `ttl` of
373 /// zero deletes it now, as Redis does. Returns whether the key existed.
374 ///
375 /// # Errors
376 ///
377 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached, and
378 /// by default, for an implementation that doesn't send it.
379 ///
380 /// ```
381 /// use std::time::Duration;
382 /// use legit_streams::{Clock, MemoryStreams, Streams};
383 ///
384 /// let clock = Clock::manual(0);
385 /// let streams = MemoryStreams::with_clock(clock.clone());
386 /// streams.xadd("reply", &[(b"k".as_slice(), b"v".as_slice())])?;
387 /// assert!(streams.expire("reply", Duration::from_secs(60))?);
388 /// clock.advance(Duration::from_secs(61));
389 /// assert_eq!(streams.xlen("reply")?, 0);
390 /// assert!(!streams.expire("reply", Duration::from_secs(60))?);
391 /// # Ok::<(), legit_streams::Error>(())
392 /// ```
393 fn expire(&self, key: &str, ttl: Duration) -> Result<bool> {
394 let _ = (key, ttl);
395 Err(unsupported("EXPIRE"))
396 }
397
398 /// `DEL key ...`: delete keys, returning how many existed.
399 ///
400 /// # Errors
401 ///
402 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached, and
403 /// by default, for an implementation that doesn't send it.
404 ///
405 /// ```
406 /// use legit_streams::{MemoryStreams, Streams};
407 ///
408 /// let streams = MemoryStreams::new();
409 /// streams.xadd("reply", &[(b"k".as_slice(), b"v".as_slice())])?;
410 /// assert_eq!(streams.del(&["reply", "missing"])?, 1);
411 /// assert_eq!(streams.xlen("reply")?, 0);
412 /// # Ok::<(), legit_streams::Error>(())
413 /// ```
414 fn del(&self, keys: &[&str]) -> Result<u64> {
415 let _ = keys;
416 Err(unsupported("DEL"))
417 }
418
419 /// `XADD` then `EXPIRE`: how a fast-lane worker writes a reply, so a reply nobody reads goes
420 /// away on its own. The expiry is set again on every add. [`RedisStreams`](crate::RedisStreams)
421 /// sends both in one round trip.
422 ///
423 /// # Errors
424 ///
425 /// [`Error::Redis`](crate::Error::Redis) when the server refuses either or can't be reached;
426 /// the entry may have been added.
427 ///
428 /// ```
429 /// use std::time::Duration;
430 /// use legit_streams::{Clock, MemoryStreams, Streams};
431 ///
432 /// let streams = MemoryStreams::with_clock(Clock::manual(0));
433 /// streams.xadd_expire("reply", &[(b"k".as_slice(), b"v".as_slice())], Duration::from_secs(60))?;
434 /// assert_eq!(streams.ttl("reply"), Some(Duration::from_secs(60)));
435 /// # Ok::<(), legit_streams::Error>(())
436 /// ```
437 fn xadd_expire(&self, stream: &str, fields: &[(&[u8], &[u8])], ttl: Duration) -> Result<EntryId> {
438 let id = self.xadd(stream, fields)?;
439 self.expire(stream, ttl)?;
440 Ok(id)
441 }
442
443 /// `XINFO GROUPS stream`: how much work a group has not finished. `None` when this
444 /// implementation can't tell, which is the default for an implementation written before this
445 /// method.
446 ///
447 /// Nothing in this crate calls it: it's for a caller that reports on a group, such as a
448 /// worker's status page, and it should be called off the path that runs tasks.
449 ///
450 /// # Errors
451 ///
452 /// [`Error::NoGroup`](crate::Error::NoGroup) when the stream or the group doesn't exist, and
453 /// [`Error::Redis`](crate::Error::Redis) when the server refuses it or can't be reached.
454 ///
455 /// ```
456 /// use legit_streams::{GroupBacklog, MemoryStreams, Streams};
457 ///
458 /// let streams = MemoryStreams::new();
459 /// streams.xgroup_create("s", "g")?;
460 /// for _ in 0..3 {
461 /// streams.xadd("s", &[(b"k".as_slice(), b"v".as_slice())])?;
462 /// }
463 /// streams.xreadgroup("s", "g", "c", 1, None)?;
464 /// assert_eq!(streams.group_backlog("s", "g")?, Some(GroupBacklog::new(1, Some(2))));
465 /// # Ok::<(), legit_streams::Error>(())
466 /// ```
467 fn group_backlog(&self, stream: &str, group: &str) -> Result<Option<GroupBacklog>> {
468 let _ = (stream, group);
469 Ok(None)
470 }
471}
472
473/// The error of a command an implementation doesn't send.
474fn unsupported(command: &str) -> crate::Error {
475 crate::Error::Redis(format!("ERR this `Streams` implementation doesn't send {command}"))
476}
477
478/// A shared handle runs the commands of what it points to, so one [`RedisStreams`](crate::RedisStreams)
479/// or a `dyn Streams` can serve many workers and readers.
480impl<S: Streams + ?Sized> Streams for std::sync::Arc<S> {
481 fn xadd(&self, stream: &str, fields: &[(&[u8], &[u8])]) -> Result<EntryId> {
482 (**self).xadd(stream, fields)
483 }
484
485 fn xlen(&self, stream: &str) -> Result<u64> {
486 (**self).xlen(stream)
487 }
488
489 fn xgroup_create(&self, stream: &str, group: &str) -> Result<bool> {
490 (**self).xgroup_create(stream, group)
491 }
492
493 fn xreadgroup(
494 &self,
495 stream: &str,
496 group: &str,
497 consumer: &str,
498 count: usize,
499 block: Option<Duration>,
500 ) -> Result<Vec<Entry>> {
501 (**self).xreadgroup(stream, group, consumer, count, block)
502 }
503
504 fn xautoclaim(
505 &self,
506 stream: &str,
507 group: &str,
508 consumer: &str,
509 min_idle: Duration,
510 start: EntryId,
511 count: usize,
512 ) -> Result<AutoClaim> {
513 (**self).xautoclaim(stream, group, consumer, min_idle, start, count)
514 }
515
516 fn xclaim_justid(
517 &self,
518 stream: &str,
519 group: &str,
520 consumer: &str,
521 ids: &[EntryId],
522 idle: Option<Duration>,
523 ) -> Result<Vec<EntryId>> {
524 (**self).xclaim_justid(stream, group, consumer, ids, idle)
525 }
526
527 fn xpending_entry(&self, stream: &str, group: &str, id: EntryId) -> Result<Option<Pending>> {
528 (**self).xpending_entry(stream, group, id)
529 }
530
531 fn xpending_consumer(&self, stream: &str, group: &str, consumer: &str, count: usize) -> Result<Vec<Pending>> {
532 (**self).xpending_consumer(stream, group, consumer, count)
533 }
534
535 fn xack(&self, stream: &str, group: &str, ids: &[EntryId]) -> Result<u64> {
536 (**self).xack(stream, group, ids)
537 }
538
539 fn xdel(&self, stream: &str, ids: &[EntryId]) -> Result<u64> {
540 (**self).xdel(stream, ids)
541 }
542
543 fn xack_xdel(&self, stream: &str, group: &str, ids: &[EntryId]) -> Result<()> {
544 (**self).xack_xdel(stream, group, ids)
545 }
546
547 fn xgroup_delconsumer(&self, stream: &str, group: &str, consumer: &str) -> Result<u64> {
548 (**self).xgroup_delconsumer(stream, group, consumer)
549 }
550
551 fn renew_lease(&self, stream: &str, group: &str, consumer: &str, id: EntryId) -> Result<Renewal> {
552 (**self).renew_lease(stream, group, consumer, id)
553 }
554
555 fn release_lease(&self, stream: &str, group: &str, consumer: &str, id: EntryId, idle: Duration) -> Result<bool> {
556 (**self).release_lease(stream, group, consumer, id, idle)
557 }
558
559 fn xread(&self, stream: &str, after: EntryId, count: usize, block: Option<Duration>) -> Result<Vec<Entry>> {
560 (**self).xread(stream, after, count, block)
561 }
562
563 fn expire(&self, key: &str, ttl: Duration) -> Result<bool> {
564 (**self).expire(key, ttl)
565 }
566
567 fn del(&self, keys: &[&str]) -> Result<u64> {
568 (**self).del(keys)
569 }
570
571 fn xadd_expire(&self, stream: &str, fields: &[(&[u8], &[u8])], ttl: Duration) -> Result<EntryId> {
572 (**self).xadd_expire(stream, fields, ttl)
573 }
574
575 fn group_backlog(&self, stream: &str, group: &str) -> Result<Option<GroupBacklog>> {
576 (**self).group_backlog(stream, group)
577 }
578}
579
580/// `ttl` in whole seconds, rounded up, as `EXPIRE` takes it.
581pub(crate) fn expire_seconds(ttl: Duration) -> u64 {
582 ttl.as_secs().saturating_add(u64::from(ttl.subsec_nanos() > 0))
583}