Documentation Index
Fetch the complete documentation index at: https://mintlify.com/backtest-kit/backtest-kit-redis-postgres-pgpool-docker/llms.txt
Use this file to discover all available pages before exploring further.
RedisService manages the ioredis connection lifecycle for the persistence layer. It exposes a single public method — waitForInit() — that resolves as soon as the underlying Redis client emits the ready event, indicating the connection is fully established and commands can be issued. All 16 cache services depend on RedisService and call waitForInit() before their first GET/SET operation.
API
Waits for the ioredis client to reach the
ready state and resolves with the connected Redis instance.- Singleshot — powered by
singleshotfromfunctools-kit. The connection attempt runs at most once; all concurrent callers share the same promise. - Fast path — if
redis.status === 'ready'at call time, the promise resolves immediately without registering any event listeners. - 15-second timeout — if the
readyevent has not fired withinCONNECTION_TIMEOUT(15 000 ms), the method throwsError("Redis connection timeout")and clears the singleshot cache so the call can be retried.
Source Code
Connection Configuration
getRedis() in src/config/redis.ts constructs the ioredis Redis client. Like getPostgres(), it is wrapped in singleshot so the same client instance is reused across all cache services.
Connection Parameters
| Environment Variable | Default | Description |
|---|---|---|
CC_REDIS_HOST | "127.0.0.1" | Redis server hostname or IP |
CC_REDIS_PORT | 6379 | Redis server port |
CC_REDIS_USER | "default" | Redis ACL username |
CC_REDIS_PASSWORD | "mysecurepassword" | Redis ACL password |
All four variables are read from
src/config/params.ts. Override them in
your deployment environment to point at a Redis Sentinel, Redis Cluster, or a
managed Redis service.Ready Detection
waitForInit() applies a two-branch check to avoid attaching a redundant event listener when the client is already healthy:
Immediate fast path
After
getRedis() returns the client instance, redis.status is checked synchronously. If it equals 'ready', the promise resolves immediately:Event-based wait with timeout
Otherwise, a
Promise.race runs between the ready-event listener and a 15-second sleep sentinel:Keepalive Ping
AsetInterval inside getRedis() issues a PING command every 30 seconds. This keeps the TCP connection alive through firewalls and load balancers that would otherwise drop idle connections:
Graceful Shutdown
When the Node.js process receivesSIGINT, the Redis connection is disconnected cleanly. The false argument to disconnect() tells ioredis to wait for pending commands to complete before closing the socket: