Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

add redis as priority option for session data

Type of Change

  • New feature

Testing

Tested manually.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Oct 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Oct 10, 2025 5:32am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 10, 2025 5:32am

@vercel vercel bot temporarily deployed to Preview – docs October 10, 2025 05:29 Inactive
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 betterAuth configuration 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 acquireLock behavior to return false when Redis is unavailable (previously returned true)

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 acquireLock function
  • 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 acquireLock behavioral change that could affect distributed locking if any code depends on it.
  • Pay attention to apps/sim/lib/redis.ts - the acquireLock function 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
Loading

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit f6c2a0f into staging Oct 10, 2025
4 of 5 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/redis-session branch October 10, 2025 05:31
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
waleedlatif1 pushed a commit that referenced this pull request Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants