-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Redis connection pool with worker affinity #136
Copy link
Copy link
Open
Labels
area/driverDatabase/cache driver infrastructureDatabase/cache driver infrastructuredriver/redisRedis driverRedis driver
Milestone
Description
Summary
Implement a connection pool for the Redis driver with the same worker-affinity model as the PostgreSQL driver. Redis connections are routed to the same engine worker as the HTTP connection.
Design
Package: driver/redis/pool.go
Pool Architecture
Same design as PostgreSQL pool:
type Pool struct {
workers []*workerPool // one per engine worker
standalone *standalonePool // fallback when no engine sharing
overflow *sharedPool // shared pool for contention overflow
pubsubPool *pubsubPool // dedicated pool for Pub/Sub connections
}Worker Affinity
Same flow as PostgreSQL:
- HTTP request on worker N →
pool.Get(ctx)checksworkers[N]first - Fallback to
overflowpool - Create new connection on worker N's event loop if needed
Release()returns toworkers[N]
Redis-Specific Considerations
- AUTH + SELECT on connect: new connections authenticated and database selected before entering pool
- Pub/Sub connections: separate pool — Pub/Sub connections are in push mode and cannot be reused for commands
- MULTI/EXEC transactions: connection held exclusively during transaction (same as PG)
- Pipeline connections: can use pooled connections — pipeline commands are atomic from Redis's perspective
Configuration
type PoolConfig struct {
MaxOpen int // max command connections (default: NumWorkers * 4)
MaxIdle int // max idle per worker (default: 2)
MaxLifetime time.Duration // max connection lifetime (default: 30m)
MaxIdleTime time.Duration // max idle time (default: 5m)
MaxPubSub int // max Pub/Sub connections (default: NumWorkers)
}Modes
client, err := redis.NewClient("localhost:6379") // standalone
client, err := redis.NewClient("localhost:6379", redis.WithEngine(srv)) // integratedAcceptance Criteria
- Per-worker pools with worker affinity
- Overflow to shared pool
- Separate Pub/Sub connection pool
- AUTH + SELECT on new connections
- Standalone mode with mini event loop
- Integrated mode sharing HTTP server's event loop
- Connection health check (PING)
-
MaxOpen,MaxIdle,MaxLifetime,MaxIdleTimeenforced - Benchmark: pool Get/Release throughput
Dependencies
- Depends on 133 (Redis client — pool manages Redis connections)
- Depends on 113 (EventLoopProvider — for integrated mode)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/driverDatabase/cache driver infrastructureDatabase/cache driver infrastructuredriver/redisRedis driverRedis driver