Better Hub uses Redis for caching GitHub API responses, reducing API rate limit consumption and improving performance. The application uses Upstash Redis for serverless-friendly Redis access via REST API.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/better-auth/better-hub/llms.txt
Use this file to discover all available pages before exploring further.
Why Redis?
Better Hub caches:- GitHub API responses - Issues, pull requests, repositories, user data
- GitHub user profiles - Authenticated user information
- GitHub ETags - For conditional API requests
- Temporary session data - Fast session lookups
Upstash Setup (Production)
Create Upstash account
Sign up at Upstash Console.
Create Redis database
- Click Create Database
- Select a region close to your application
- Choose Regional (or Global for multi-region)
- Enable TLS (recommended)
Get REST credentials
In your database dashboard, find:
- REST URL:
https://[endpoint].upstash.io - REST Token: Your authentication token
Local Development Setup
Option 1: Docker Compose (Recommended)
Run Redis locally with serverless-redis-http proxy:Start Redis with Docker Compose
- Redis on port
6379 - serverless-redis-http proxy on port
8079
Option 2: Upstash Free Tier
Use Upstash free tier for development:- 10,000 commands/day
- 256 MB storage
- Perfect for development and testing
Redis Client Configuration
Better Hub uses@upstash/redis for serverless-optimized Redis access.
Client Initialization
apps/web/src/lib/redis.ts.
Caching GitHub API Responses
apps/web/src/lib/auth.ts:19-26.
Caching Strategies
GitHub User Data
Cache Key:github_user:{token_hash}
TTL: 1 hour
Purpose: Avoid repeated GET /user API calls
GitHub API Responses
Cache Key:github:{userId}:{endpoint}:{params_hash}
TTL: Varies by endpoint (5 minutes to 24 hours)
Purpose: Cache repository data, issues, PRs, etc.
ETag-Based Conditional Caching
GitHub API supports ETags for conditional requests:Cache Invalidation
Manual Invalidation
Invalidate specific cache entries:Pattern-Based Invalidation
Invalidate all caches for a user:TTL-Based Expiration
Most caches use automatic TTL expiration:- Short-lived data (issues, PRs): 5-15 minutes
- Medium-lived data (repositories, users): 30-60 minutes
- Long-lived data (organization info): 24 hours
Performance Optimization
Batch Operations
Use pipeline for multiple operations:JSON Compression
Compress large JSON before caching:Cache Warming
Pre-populate cache for common queries:Monitoring and Debugging
Upstash Console
Monitor Redis usage in Upstash Console:- Commands/sec - Request rate
- Storage - Memory usage
- Latency - Response times
- Slow commands - Performance bottlenecks
Cache Hit Rate
Track cache effectiveness:Debug Logging
Log cache operations in development:Cost Optimization
Upstash Pricing
Upstash bills based on:- Commands - Number of Redis commands executed
- Storage - Data stored in memory
- Bandwidth - Data transfer
- 10,000 commands/day
- 256 MB storage
- $0.20 per 100K commands
- $0.25 per GB storage
Reduce Costs
Security
REST API Security
Data Encryption
Upstash Redis supports:- TLS encryption in transit - Enabled by default on REST API
- Encryption at rest - Available on paid plans
Troubleshooting
Connection Failed
Error:Failed to fetch or connection timeout
Solutions:
- Verify
UPSTASH_REDIS_REST_URLis correct - Check
UPSTASH_REDIS_REST_TOKENis valid - Ensure no firewall blocking outbound HTTPS
- For local development, verify Docker container is running
Authentication Error
Error:Unauthorized or Invalid token
Solutions:
- Regenerate REST token in Upstash Console
- Verify no extra spaces in
.envfile - Check token hasn’t expired (tokens don’t expire by default)
Rate Limit Exceeded
Error:Too many requests
Solutions:
- Upgrade Upstash plan
- Optimize number of Redis commands (use pipelines)
- Increase cache TTLs to reduce churn
Memory Limit Exceeded
Error:OOM or storage limit
Solutions:
- Enable eviction policy:
allkeys-lru(evict least recently used) - Reduce TTLs for large objects
- Compress data before caching
- Upgrade to larger plan
Advanced Configuration
Custom Eviction Policy
Configure in Upstash Console:- noeviction - Return errors when memory limit reached
- allkeys-lru - Evict least recently used keys (recommended)
- allkeys-lfu - Evict least frequently used keys
- volatile-ttl - Evict keys with shortest TTL
Global Replication
Upstash supports multi-region replication:- Create Global Database in Upstash Console
- Select primary and replica regions
- Use same REST URL - Upstash routes to nearest region