fix(stream): fix XPENDING bug and add exclusive range support #3277
+333
−3
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.
English / 中文
Fix XPENDING Bug and Add Exclusive Range Support
Summary
This PR fixes a critical bug in the
XPENDINGcommand and implements the missing exclusive range support feature introduced in Redis 6.2.0.Issues Fixed
Fixes #3276
Changes
1. Bug Fix: Empty Results When start_id == end_id
Problem:
XPENDINGincorrectly returned an empty list when querying a single entry (start_id equals end_id), even though the pending entry existed.Root Causes:
cmd_stream.cc,CommandXPending::Parseincorrectly usedstart_idto parse theend_idparameterredis_stream.cc,GetPendingEntriesused an exclusive upper bound for iteration, excluding entries atend_idFixes Applied:
end_idparameter correctlyend_idrocksdb::Sliceto avoid string allocation2. Feature: Exclusive Range Support
Implementation: Added support for exclusive ranges using
(prefix as specified in Redis 6.2.0 documentation.Changes:
exclude_startandexclude_endflags toStreamPendingOptionsstructCommandXPending::Parseto detect and handle(prefixGetPendingEntriesiteration logic to respect exclusion flagsUsage Examples:
Testing
Added comprehensive test suite in
tests/gocase/unit/type/stream/xpending_test.gocovering:All tests pass successfully.
Files Changed
src/commands/cmd_stream.cc: Fixed parsing and added exclusive range handlingsrc/types/redis_stream.cc: Fixed iteration bounds and optimized single-entry lookupsrc/types/redis_stream_base.h: Added exclusion flags to StreamPendingOptionstests/gocase/unit/type/stream/xpending_test.go: Comprehensive test coverage修复 XPENDING 错误并添加排除范围支持
概述
本 PR 修复了
XPENDING命令的一个严重错误,并实现了 Redis 6.2.0 中引入的排除范围功能。修复的问题
修复 #3276
更改内容
1. 错误修复:当 start_id == end_id 时返回空结果
问题描述:当查询单个条目(start_id 等于 end_id)时,
XPENDING错误地返回空列表,即使待处理条目存在。根本原因:
cmd_stream.cc中,CommandXPending::Parse错误地使用start_id来解析end_id参数redis_stream.cc中,GetPendingEntries使用了排除性的上界进行迭代,导致end_id处的条目被排除应用的修复:
end_id参数end_idrocksdb::Slice优化循环比较以避免字符串分配2. 功能:排除范围支持
实现内容:按照 Redis 6.2.0 文档的规范,使用
(前缀添加了排除范围支持。变更:
StreamPendingOptions结构体中添加了exclude_start和exclude_end标志CommandXPending::Parse以检测和处理(前缀GetPendingEntries迭代逻辑以遵守排除标志使用示例:
测试
在
tests/gocase/unit/type/stream/xpending_test.go中添加了全面的测试套件,涵盖:所有测试均成功通过。
修改的文件
src/commands/cmd_stream.cc:修复解析并添加排除范围处理src/types/redis_stream.cc:修复迭代边界并优化单条目查询src/types/redis_stream_base.h:为 StreamPendingOptions 添加排除标志tests/gocase/unit/type/stream/xpending_test.go:全面的测试覆盖