Shared Redis client for rate limiting, token revocation, and SSE pub/sub.
When REDIS_URL is set, creates an ioredis client and a separate subscriber
client (Redis requires dedicated connections for pub/sub). When REDIS_URL is
not set, all exports are no-ops / in-memory fallbacks so the application works
identically in single-instance mode without Redis.
Exports
redis— Primary client for GET/SET/DEL commands (ornull).redisSub— Subscriber client for pub/sub (ornull).isRedisAvailable—truewhen a live Redis connection exists.closeRedis— Gracefully disconnect both clients (shutdown hook).
Usage
import { redis, isRedisAvailable } from "../utils/redisClient.js";
if (isRedisAvailable()) {
await redis.set("key", "value", "EX", 3600);
}
- Source:
Members
(static) redis :Object|null
Primary ioredis client for commands.
Type:
- Object | null
- Source:
(static) redisSub :Object|null
Dedicated subscriber client for pub/sub.
Type:
- Object | null
- Source:
Methods
(static) closeRedis() → {Promise.<void>}
Gracefully disconnect both Redis clients.
Called from the shutdown hook in index.js.
- Source:
Returns:
- Type
- Promise.<void>
(static) isRedisAvailable() → {boolean}
Check whether a live Redis connection is available.
- Source:
Returns:
true when the primary client is connected.
- Type
- boolean