feat(cache): implement database fallback for conversation sequence management
Improve the reliability of conversation sequence generation by implementing a fallback mechanism to the database when Redis is unavailable or when keys are missing. - Add `GetNextSeq` to `MessageRepository` and implement it in `MessageRepositoryAdapter`. - Update `ConversationCache` to fallback to DB in `GetConvMaxSeq`, `GetConvMaxSeqBatch`, and `GetNextSeq`. - Ensure Redis TTL is refreshed after every `INCR` operation to prevent sequence counter expiration. - Refactor service layers to handle sequence generation errors more explicitly. - Add `IsEnabled` helper to `LayeredCache` for cleaner availability checks.
This commit is contained in:
5
internal/cache/repository_adapter.go
vendored
5
internal/cache/repository_adapter.go
vendored
@@ -74,3 +74,8 @@ func (a *MessageRepositoryAdapter) CreateMessage(msg *model.Message) error {
|
||||
func (a *MessageRepositoryAdapter) UpdateConversationLastSeq(convID string, seq int64) error {
|
||||
return a.repo.UpdateConversationLastSeq(convID, seq)
|
||||
}
|
||||
|
||||
// GetNextSeq 实现 MessageRepository 接口
|
||||
func (a *MessageRepositoryAdapter) GetNextSeq(convID string) (int64, error) {
|
||||
return a.repo.GetNextSeq(convID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user