-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(sessions): add redis as priority option for session data #1592
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
Merged
Conversation
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
Contributor
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.
Greptile Overview
Summary
Added Redis as an optional secondary storage layer for session data in the authentication system, providing performance benefits through caching while maintaining PostgreSQL as the primary storage.
Key Changes:
- Configured Redis as secondary storage in
betterAuthconfiguration with error handling for get/set/delete operations - Removed in-memory fallback cache from
redis.ts, simplifying the codebase and making Redis behavior more explicit - Changed
acquireLockbehavior to returnfalsewhen Redis is unavailable (previously returnedtrue)
Impact:
- Sessions will be cached in Redis when available, reducing database load
- System gracefully falls back to PostgreSQL when Redis is unavailable
- Lock acquisition behavior changed - operations requiring locks will fail when Redis is down instead of proceeding
Confidence Score: 4/5
- Safe to merge with one behavioral change to verify in
acquireLockfunction - Implementation is solid with proper error handling and graceful degradation. The Redis secondary storage is correctly configured with try-catch blocks. Main concern is the
acquireLockbehavioral change that could affect distributed locking if any code depends on it. - Pay attention to
apps/sim/lib/redis.ts- theacquireLockfunction behavior changed from allowing operations when Redis is unavailable to blocking them
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/lib/auth.ts | 4/5 | Added Redis as optional secondary storage for session data with proper error handling and conditional configuration |
| apps/sim/lib/redis.ts | 4/5 | Removed in-memory fallback cache, simplified code by removing comments, changed acquireLock behavior when Redis unavailable |
Sequence Diagram
sequenceDiagram
participant Client
participant BetterAuth
participant PostgreSQL
participant Redis
Note over Client,Redis: Session Creation
Client->>BetterAuth: Create Session
BetterAuth->>PostgreSQL: Store session data
BetterAuth->>Redis: Cache session (if available)
BetterAuth-->>Client: Session created
Note over Client,Redis: Session Read
Client->>BetterAuth: Get Session
BetterAuth->>Redis: Try cache lookup
alt Cache Hit
Redis-->>BetterAuth: Return cached data
else Cache Miss or Unavailable
BetterAuth->>PostgreSQL: Query database
PostgreSQL-->>BetterAuth: Return session data
end
BetterAuth-->>Client: Return session
Note over Client,Redis: Session Deletion
Client->>BetterAuth: Delete Session
BetterAuth->>PostgreSQL: Remove from database
BetterAuth->>Redis: Remove from cache (if available)
BetterAuth-->>Client: Session deleted
2 files reviewed, 1 comment
waleedlatif1
added a commit
that referenced
this pull request
Oct 11, 2025
* feat(sessions): add redis as priority option for session data * update chat client otp
10 tasks
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.
Summary
add redis as priority option for session data
Type of Change
Testing
Tested manually.
Checklist