fix(stream): align XPENDING ID parsing and PEL range with XRANGE (incomplete IDs, exclusive bounds)#3437
Open
songqing wants to merge 7 commits intoapache:unstablefrom
Open
fix(stream): align XPENDING ID parsing and PEL range with XRANGE (incomplete IDs, exclusive bounds)#3437songqing wants to merge 7 commits intoapache:unstablefrom
songqing wants to merge 7 commits intoapache:unstablefrom
Conversation
Member
|
@songqing Good catch. |
git-hulk
reviewed
Apr 10, 2026
jihuayu
reviewed
Apr 10, 2026
Member
There was a problem hiding this comment.
The behavior of XPENDING seems to differ slightly from Redis. Could you take a look at these two failing test cases?
t.Run("XPENDING with incomplete end ID should include the whole millisecond", func(t *testing.T) {
streamKey := "xpending-incomplete-end-test"
group := "grp"
consumer := "con"
ids := []string{"1-0", "1-1", "1-2"}
require.NoError(t, rdb.Del(ctx, streamKey).Err())
for i, id := range ids {
require.NoError(t, rdb.XAdd(ctx, &redis.XAddArgs{Stream: streamKey, ID: id, Values: []string{"f", strconv.Itoa(i)}}).Err())
}
require.NoError(t, rdb.XGroupCreateMkStream(ctx, streamKey, group, "0").Err())
_, err := rdb.XReadGroup(ctx, &redis.XReadGroupArgs{Group: group, Consumer: consumer, Streams: []string{streamKey, ">"}, Count: 10}).Result()
require.NoError(t, err)
result, err := rdb.Do(ctx, "XPENDING", streamKey, group, "1", "1", "10").Result()
require.NoError(t, err)
entries, ok := result.([]interface{})
require.True(t, ok)
require.Len(t, entries, 3, "XPENDING 1 1 should include every pending entry in millisecond 1, matching Redis")
for i, entry := range entries {
fields, ok := entry.([]interface{})
require.True(t, ok)
require.Len(t, fields, 4)
gotID, ok := fields[0].(string)
require.True(t, ok)
require.Equal(t, ids[i], gotID)
gotConsumer, ok := fields[1].(string)
require.True(t, ok)
require.Equal(t, consumer, gotConsumer)
require.GreaterOrEqual(t, fields[2], int64(0))
require.EqualValues(t, 1, fields[3])
}
require.NoError(t, rdb.Del(ctx, streamKey).Err())
})
t.Run("XPENDING with exclusive start should match Redis", func(t *testing.T) {
streamKey := "xpending-exclusive-start-test"
group := "grp"
consumer := "con"
ids := []string{"1-0", "1-1", "1-2"}
require.NoError(t, rdb.Del(ctx, streamKey).Err())
for i, id := range ids {
require.NoError(t, rdb.XAdd(ctx, &redis.XAddArgs{Stream: streamKey, ID: id, Values: []string{"f", strconv.Itoa(i)}}).Err())
}
require.NoError(t, rdb.XGroupCreateMkStream(ctx, streamKey, group, "0").Err())
_, err := rdb.XReadGroup(ctx, &redis.XReadGroupArgs{Group: group, Consumer: consumer, Streams: []string{streamKey, ">"}, Count: 10}).Result()
require.NoError(t, err)
result, err := rdb.Do(ctx, "XPENDING", streamKey, group, "(1-0", "+", "10").Result()
require.NoError(t, err)
entries, ok := result.([]interface{})
require.True(t, ok)
require.Len(t, entries, 2, "XPENDING (1-0 + 10 should exclude the first pending entry, matching Redis")
for i, entry := range entries {
fields, ok := entry.([]interface{})
require.True(t, ok)
require.Len(t, fields, 4)
gotID, ok := fields[0].(string)
require.True(t, ok)
require.Equal(t, ids[i+1], gotID)
gotConsumer, ok := fields[1].(string)
require.True(t, ok)
require.Equal(t, consumer, gotConsumer)
require.GreaterOrEqual(t, fields[2], int64(0))
require.EqualValues(t, 1, fields[3])
}
require.NoError(t, rdb.Del(ctx, streamKey).Err())
})
Contributor
Author
ok, there still has another bug, fixed together. |
007af9f to
41cab00
Compare
jihuayu
approved these changes
Apr 10, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



XPENDING extended form must use the same start/end ID rules as XRANGE:
parse the end with ParseRangeEnd so a bare millisecond includes all
sequence numbers in that ms; accept '(' for exclusive start/end and
honor them when scanning the pending entry list.
Refs: https://redis.io/docs/latest/commands/xpending/ ("in a similar way we do it with XRANGE")
Refs: https://redis.io/docs/latest/commands/xrange/ ("closed interval" / inclusive unless '(' prefix)