Skip to content

feat(streams): Add the possibility to have per stream ids - #3793

Open
ndyakov wants to merge 8 commits into
masterfrom
ndyakov/stream-ids
Open

feat(streams): Add the possibility to have per stream ids#3793
ndyakov wants to merge 8 commits into
masterfrom
ndyakov/stream-ids

Conversation

@ndyakov

@ndyakov ndyakov commented Apr 24, 2026

Copy link
Copy Markdown
Member

fixes #3694


Note

Low Risk
Additive, backward-compatible API on stream command building with validation; no auth or data-model changes.

Overview
Adds XReadArgs.IDs so XRead can resume each stream from a different ID while Streams lists only stream keys (fixes #3694). When IDs is set it is appended to the Redis command and overrides the existing single ID field; the inline Streams shape (keys plus IDs in one slice) is unchanged.

XRead now returns a client error without sending a command if IDs is non-empty but its length does not match Streams. Docs on XReadArgs describe the two supported argument shapes.

Coverage includes integration specs for per-stream reads, precedence over ID, and the mismatch error, plus unit tests for argument assembly and firstKeyPos.

Reviewed by Cursor Bugbot for commit 7d9af19. Bugbot is set up for automated code reviews on this repo. Configure here.

@jit-ci

jit-ci Bot commented Apr 24, 2026

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds per-stream resume IDs support for XREAD to address #3694, enabling callers to specify different IDs for each stream.

Changes:

  • Extends XReadArgs with IDs []string (per-stream IDs) and documents precedence over ID.
  • Updates XRead argument construction to append per-stream IDs when provided.
  • Adds tests for per-stream IDs and for IDs precedence over ID.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
stream_commands.go Adds XReadArgs.IDs and updates XRead arg building logic to support per-stream IDs.
commands_test.go Adds test coverage for per-stream IDs and precedence behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stream_commands.go Outdated
Comment on lines +196 to +205
Streams []string // list of streams, or streams and ids e.g. stream1 stream2 id1 id2
Count int64
Block time.Duration
ID string
// ID is a single ID applied to every stream in Streams.
// When reading from multiple streams that require different IDs,
// use IDs instead so each stream can be resumed from its own last ID.
ID string
// IDs is the per-stream list of IDs (one per entry in Streams).
// When non-empty, IDs takes precedence over ID.
IDs []string

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Streams field comment says it can contain both stream names and IDs, but IDs is documented as "one per entry in Streams" (which only makes sense if Streams contains stream names only). This is contradictory and will confuse callers, especially now that there are multiple supported input shapes. Please clarify the docs to explicitly describe the supported encodings (legacy Streams containing keys+ids vs Streams containing only keys when using ID/IDs) and how they interact/are mutually exclusive.

Copilot uses AI. Check for mistakes.
Comment thread stream_commands.go
Comment on lines +228 to +233
switch {
case len(a.IDs) > 0:
for _, id := range a.IDs {
args = append(args, id)
}
case a.ID != "":

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When IDs is non-empty, the code appends all IDs without checking that the count matches the number of stream keys being read. If these lengths differ, Redis will return a generic arity error that can be hard to diagnose. Consider validating len(a.IDs) == len(a.Streams) when IDs is used and returning a client-side error (e.g., via cmd.SetErr) with a clear message.

Copilot uses AI. Check for mistakes.
ndyakov and others added 6 commits May 19, 2026 14:59
- ID doc claimed the inline form is auto-detected; it must be left
  empty when Streams carries ids inline, or the command is malformed
- add wire-format unit tests for keys+IDs, firstKeyPos, and the
  length-mismatch error path
- set Block: -1 in new integration tests so a regression fails fast
  instead of blocking forever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XREAD accept multiple streams but only one id resulting multiple issues

2 participants