c1ef717d17
- shared/cache: add Options/L1/async/metrics/prefix decorators, multi-key ops, Redis pool tuning, and JSON readthrough metrics - worker-generate: claim tasks via DB lease + heartbeat, requeue stale queued tasks, expire dead leases with refund/cache invalidation - tenant: version article cache keys so worker recovery invalidations propagate cleanly - shared/config: expand Redis (pool/timeouts/TLS) and Generation (lease/recovery) configs with defaults Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
37 lines
859 B
Go
37 lines
859 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
goredis "github.com/redis/go-redis/v9"
|
|
|
|
"github.com/geo-platform/tenant-api/internal/shared/config"
|
|
)
|
|
|
|
func NewClient(ctx context.Context, cfg config.RedisConfig) (*goredis.Client, error) {
|
|
client := NewLazyClient(cfg)
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
|
return nil, fmt.Errorf("ping redis: %w", err)
|
|
}
|
|
|
|
return client, nil
|
|
}
|
|
|
|
func NewLazyClient(cfg config.RedisConfig) *goredis.Client {
|
|
client := goredis.NewClient(&goredis.Options{
|
|
Addr: cfg.Addr,
|
|
Password: cfg.Password,
|
|
DB: cfg.DB,
|
|
DialTimeout: cfg.DialTimeout,
|
|
ReadTimeout: cfg.ReadTimeout,
|
|
WriteTimeout: cfg.WriteTimeout,
|
|
PoolSize: cfg.PoolSize,
|
|
MinIdleConns: cfg.MinIdleConns,
|
|
MaxRetries: cfg.MaxRetries,
|
|
PoolTimeout: cfg.PoolTimeout,
|
|
TLSConfig: cfg.TLSConfig(),
|
|
})
|
|
return client
|
|
}
|