-
-
Notifications
You must be signed in to change notification settings - Fork 162
[cttq] fix: When create redis_conn,check if connection already exists #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[cttq] fix: When create redis_conn,check if connection already exists #268
Conversation
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
修复当使用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: