Skip to main content
NEW in v2.1.0 - Enterprise session management with Redis for stateful authentication and concurrent session control.

Overview

Redis provides production-grade session storage with:
  • Persistent Sessions - Survive server restarts
  • Distributed Sessions - Share across multiple instances
  • Sliding Expiration - Extend sessions on user activity
  • Concurrent Limits - Control max sessions per user
  • Instant Revocation - Immediate logout across all devices
  • Session Analytics - Track active users and session patterns

Why Redis Sessions?

Token-based (Stateless)

Best for: Serverless, Cloud Run, stateless architectures
  • No server storage required
  • Lower infrastructure costs
  • Simpler deployment
  • Cannot revoke individual tokens

Session-based (Stateful)

Best for: Enterprise apps, multi-instance deployments
  • Longer session lifetimes (24+ hours)
  • Instant revocation
  • Concurrent session limits
  • User session tracking

Quick Start

1

Deploy Redis

2

Configure Application

Always use SSL/TLS in production: Set REDIS_SSL=true and use rediss:// URL scheme.
3

Test Session Store

4

Verify in Redis

Session Lifecycle

Session Configuration

Session TTL

Fixed TTL: Session expires exactly after TTL, regardless of activity. Sliding Window: Session extends on each request, up to max TTL.

Concurrent Sessions

Use cases:
  • 1 session: Single device login (revokes other devices)
  • 3-5 sessions: Normal multi-device usage
  • Unlimited: Set to 0 or omit

Session Metadata

Store additional context with sessions:
Access metadata:

API Operations

Create Session

Get Session

Refresh Session

Revoke Session

Session Analytics

Integration with Authentication

Keycloak + Redis Sessions

Production Deployment

High Availability

Deploy Redis with replication:

redis.conf

save 900 1 # Save after 900s if >= 1 key changed save 300 10 # Save after 300s if >= 10 keys changed save 60 10000 # Save after 60s if >= 10000 keys changed

AOF (append-only file) for durability

appendonly yes appendfsync everysec

Always use password

REDIS_PASSWORD=strong-random-password requirepass strong-random-password

TLS/SSL in production

REDIS_SSL=true REDIS_URL=rediss://redis-session:6380/0

Redis 6+ with ACL

REDIS_USERNAME=sessions REDIS_PASSWORD=password

redis.conf

maxmemory 2gb maxmemory-policy allkeys-lru # Evict least recently used

Or volatile-lru (evict only keys with TTL)

maxmemory-policy volatile-lru

Monitoring

Key metrics to track:
Alerts:
  • Memory usage > 80%
  • Evicted keys > 0
  • Hit ratio < 90%
  • Replication lag > 5s

Troubleshooting

Error: NOAUTH Authentication requiredSolutions:
  • Check REDIS_PASSWORD environment variable
  • Verify redis.conf has requirepass set
  • Use -a password flag with redis-cli
Possible causes:
  • Session expired (check TTL)
  • Redis evicted key (memory full)
  • Wrong Redis database (check /0 in URL)
  • Session was revoked
Debug:
Solutions:
  1. Reduce TTL: Lower SESSION_TTL_SECONDS
  2. Enable eviction: Set maxmemory-policy allkeys-lru
  3. Increase memory: Scale up Redis instance
  4. Clean expired: Redis auto-expires, but run FLUSHDB if needed
Check current usage:
Performance tuning:
  • Use connection pooling (automatic in Python redis client)
  • Enable pipelining for batch operations
  • Use local Redis instance (reduce network latency)
  • Check Redis logs for slow queries

Migration from Token-based

Switching from stateless tokens to Redis sessions:
1

Deploy Redis

Deploy Redis instance (see Quick Start above)
2

Update Configuration

3

Dual Mode Support (Optional)

Support both tokens and sessions during migration:
4

Update Client Applications

Migrate clients from token to session:Before (Token):
After (Session):
5

Deprecate Token Support

After migration period, remove token support:

Next Steps

Authentication

Configure session mode authentication

Keycloak SSO

Integrate Keycloak with sessions

Kubernetes Deployment

Deploy Redis on Kubernetes

Production Checklist

Session security best practices

Production Ready: Redis sessions provide enterprise-grade session management with instant revocation and multi-device support!