feat(idgen): 为 Sequencer 添加 Set 和 SetIfNotExists 方法#28
Merged
Conversation
- 在 Sequencer 接口添加 Set 和 SetIfNotExists 方法 - Set: 直接设置序列号的值,覆盖现有值 - SetIfNotExists: 仅当键不存在时设置,返回 bool 表示是否设置成功 - 两个方法均对负值进行校验 - 添加完整的单元测试,包括 IM 场景的初始化测试 - 解决 issue #27 中描述的序列号初始化需求 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
概述
为
idgen.Sequencer接口添加Set和SetIfNotExists方法,解决 issue #27 中描述的序列号初始化需求。变更内容
接口变更 (idgen.go)
实现细节 (sequence.go)
Set: 直接设置序列号值,使用 RedisSET命令,会覆盖现有值SetIfNotExists: 仅当键不存在时设置,使用 RedisSETNX命令,返回 bool 表示是否设置成功ErrInvalidInput错误测试覆盖 (idgen_test.go)
TestSequencer_Set: 基本设置、负值校验、覆盖行为、前缀处理TestSequencer_SetIfNotExists: 新键设置、已存在键处理、负值校验、IM 场景模拟使用场景
IM 系统中会话消息序列号初始化:
测试
所有测试通过:
Closes #27
🤖 Generated with Claude Code