[cttq] fix: When create redis_conn,check if connection already exists#268
Open
warning128 wants to merge 1 commit intoAmoyLab:mainfrom
Open
[cttq] fix: When create redis_conn,check if connection already exists#268warning128 wants to merge 1 commit intoAmoyLab:mainfrom
warning128 wants to merge 1 commit intoAmoyLab:mainfrom
Conversation
Contributor
Reviewer's GuideAdds a pre-fetch check in RedisStore.Get to reuse existing connections from the active connections map and renew their TTLs, ensuring consistent session usage without recreating connections each time. Sequence diagram for RedisStore.Get connection reuse and TTL renewalsequenceDiagram
participant "Caller"
participant "RedisStore"
participant "RedisClient"
participant "Logger"
"Caller"->>"RedisStore": Get(ctx, id)
activate "RedisStore"
"RedisStore"->>"RedisStore": Check connections[id]
alt Connection exists
"RedisStore"->>"RedisClient": Expire(key, ttl)
"RedisClient"-->>"RedisStore": (result)
alt Expire error
"RedisStore"->>"Logger": Warn("failed to renew session TTL")
end
"RedisStore"->>"RedisClient": Expire(prefix+"ids", ttl)
"RedisClient"-->>"RedisStore": (result)
alt Expire error
"RedisStore"->>"Logger": Warn("failed to renew session ID set TTL")
end
"RedisStore"-->>"Caller": conn
else Connection does not exist
"RedisStore"->>"RedisClient": Get(key)
"RedisClient"-->>"RedisStore": data
... (rest of original logic)
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Consider using defer to release the read lock right after acquiring it to simplify control flow and prevent accidental double-unlock.
- Extract the TTL renewal calls into a helper method to reduce duplication and centralize session expiration logic.
- Ensure expired connections are removed from s.connections elsewhere to prevent stale entries and potential memory leaks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using defer to release the read lock right after acquiring it to simplify control flow and prevent accidental double-unlock.
- Extract the TTL renewal calls into a helper method to reduce duplication and centralize session expiration logic.
- Ensure expired connections are removed from s.connections elsewhere to prevent stale entries and potential memory leaks.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
修复当使用redis 作为 session_conn时,发送事件Queue与处理事件的conn不一致的问题
Fixes #267
Summary by Sourcery
Reuse existing Redis session connections in RedisStore.Get and renew TTL for sessions and ID sets to fix inconsistent session connections when using Redis for sessions.
Bug Fixes:
Enhancements: