Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Because ReRu is pre-1.0, minor versions may include breaking changes.
- `GETEX` validates option syntax first, then the key and type, and only then
the expiry value, so a missing key replies nil and a wrong type replies
WRONGTYPE without value errors.
- `XINFO STREAM` compares `FULL` and `COUNT` as C strings, treats `COUNT 0` as
unlimited, and falls back to the default count of 10 for a negative count.
- `XINFO STREAM` argument-shape errors and per-group `NOGROUP` texts match
Redis: `XGROUP`/`XINFO CONSUMERS` name the missing group, `XPENDING` keeps the
combined key/group text, and malformed `XINFO STREAM` shapes report the
Expand Down
5 changes: 2 additions & 3 deletions docs/COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ Stream IDs are parsed as C strings: leading whitespace, a leading `+`, leading
zeros, and a NUL terminator are accepted, while trailing bytes are not. Stream
subcommand arity errors name the command or `parent|subcommand`, and unknown
subcommands are reported. A few stream keyword comparisons remain exact rather
than C-string (`XADD`/`XTRIM`/`XGROUP`/`XAUTOCLAIM` and `XINFO` options with a
NUL suffix),
than C-string (`XADD`/`XTRIM`/`XGROUP`/`XAUTOCLAIM` options with a NUL suffix),
`XAUTOCLAIM`'s start ID, `XGROUP SETID`, and `XREAD` IDs do not accept `+`/`-`,
`XGROUP DESTROY` on a missing key replies 0, `ENTRIESREAD` uses the generic
integer error and its reporting differs from Redis, and some `XTRIM`/`XREAD`
Expand All @@ -401,7 +400,7 @@ nothing. These provide at-least-once processing primitives, not exactly-once
application execution.

`XINFO GROUPS/CONSUMERS/STREAM` exposes group cursors, pending counts, consumers,
entry counters and stream endpoints. STREAM FULL accepts COUNT (zero means all)
entry counters and stream endpoints. STREAM FULL accepts COUNT (zero means all; a negative count uses the default 10)
and returns entries plus group/consumer pending lists with delivery timestamps.
ReRu uses a vector for streams: both radix-tree allocation metrics report zero.
Consumer diagnostics include the Redis 7.2+ inactive/active-time fields. Newer
Expand Down
19 changes: 13 additions & 6 deletions src/stream_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,19 +883,26 @@ fn group_lag(stream: &Stream, group: &Group) -> Option<u64> {
fn stream_info(c: &[Vec<u8>], store: &Store) -> Result<Vec<u8>> {
let mut entries = store.entries.lock().unwrap();
let stream = stream_mut(&mut entries, &c[2])?;
let full = c.get(3).is_some_and(|v| v.eq_ignore_ascii_case(b"FULL"));
let full = c.get(3).is_some_and(|v| cstr_eq(v, b"FULL"));
let count = match c.len() {
3 => 10,
4 if full => 10,
6 if full && c[4].eq_ignore_ascii_case(b"COUNT") => number(&c[5])? as usize,
6 if full && cstr_eq(&c[4], b"COUNT") => {
match protocol::parse_int(&c[5]) {
None => return Err(protocol::error("value is not an integer or out of range")),
// Zero means every entry; a negative count falls back to 10.
Some(0) => usize::MAX,
Some(value) if value < 0 => 10,
Some(value) => usize::try_from(value).unwrap_or(usize::MAX),
}
}
_ => {
return Err(protocol::error(&format!(
"unknown subcommand or wrong number of arguments for '{}'. Try XINFO HELP.",
String::from_utf8_lossy(sub_token(c).unwrap_or(b""))
)))
}
};
let limit = if count == 0 { usize::MAX } else { count };
let mut fields = vec![
protocol::bulk(b"length"),
integer(stream.entries.len() as u64),
Expand Down Expand Up @@ -943,7 +950,7 @@ fn stream_info(c: &[Vec<u8>], store: &Store) -> Result<Vec<u8>> {
stream
.entries
.iter()
.take(limit)
.take(count)
.map(|entry| entry_reply(entry.id, Some(entry)))
.collect(),
),
Expand All @@ -957,7 +964,7 @@ fn stream_info(c: &[Vec<u8>], store: &Store) -> Result<Vec<u8>> {
group
.pending
.iter()
.take(limit)
.take(count)
.map(|(id, pending)| {
array(vec![
protocol::bulk(id.to_string().as_bytes()),
Expand Down Expand Up @@ -993,7 +1000,7 @@ fn stream_info(c: &[Vec<u8>], store: &Store) -> Result<Vec<u8>> {
array(
owned
.into_iter()
.take(limit)
.take(count)
.map(|(id, pending)| {
array(vec![
protocol::bulk(id.to_string().as_bytes()),
Expand Down
52 changes: 48 additions & 4 deletions tests/stream_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,17 @@ fn stream_diagnostics_include_pending_owners_limits_and_deleted_metadata() {
c.call(&[b"XINFO", b"STREAM", b"s", b"COUNT", b"1"]),
Reply::Error(_)
));
assert!(matches!(
c.call(&[b"XINFO", b"STREAM", b"s", b"FULL", b"COUNT", b"-1"]),
Reply::Error(_)
));
let full = c.call(&[b"XINFO", b"STREAM", b"s", b"FULL", b"COUNT", b"-1"]);
assert_eq!(rows(field(&full, b"entries")).len(), 2);
let full = c.call(&[
b"XINFO",
b"STREAM",
b"s",
b"FULL\x00junk",
b"COUNT\x00junk",
b"1",
]);
assert_eq!(rows(field(&full, b"entries")).len(), 1);
c.call(&[b"MULTI"]);
c.call(&[b"XLEN", b"s"]);
assert_eq!(c.call(&[b"EXEC"]), array(vec![integer(2)]));
Expand Down Expand Up @@ -1754,3 +1761,40 @@ fn stream_group_texts_name_the_group_and_xinfo_stream_shapes() {
Reply::Error(b"ERR unknown subcommand 'stream'. Try XINFO HELP.".to_vec())
);
}

#[test]
fn xinfo_stream_count_zero_is_unlimited_and_negative_uses_the_default() {
let server = Server::start();
let mut c = Client::new(&server);
for index in 1..=11 {
let id = format!("{index}-0");
assert!(matches!(
c.call(&[b"XADD", b"big", id.as_bytes(), b"f", b"v"]),
Reply::Bulk(Some(_))
));
}

for count in [b"-1".as_slice(), b"-100", b"-9223372036854775808"] {
let full = c.call(&[b"XINFO", b"STREAM", b"big", b"FULL", b"COUNT", count]);
assert_eq!(
rows(field(&full, b"entries")).len(),
10,
"{count:?} must fall back to the default count"
);
}
for count in [b"0".as_slice(), b"9223372036854775807"] {
let full = c.call(&[b"XINFO", b"STREAM", b"big", b"FULL", b"COUNT", count]);
assert_eq!(rows(field(&full, b"entries")).len(), 11, "{count:?}");
}
assert_eq!(
c.call(&[
b"XINFO",
b"STREAM",
b"big",
b"FULL",
b"COUNT",
b"9223372036854775808",
]),
Reply::Error(b"ERR value is not an integer or out of range".to_vec())
);
}
Loading