Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 11s
Build & Deploy / 🧪 QA (push) Successful in 1m18s
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🏗️ Build (push) Has been cancelled
CI - Lint, Typecheck & Test / quality-assurance (pull_request) Failing after 3m55s
23 lines
575 B
TypeScript
23 lines
575 B
TypeScript
import Redis from 'ioredis';
|
|
|
|
const isDockerContainer =
|
|
process.env.IS_DOCKER === 'true' || process.env.HOSTNAME?.includes('klz-app');
|
|
const redisUrl =
|
|
process.env.REDIS_URL ||
|
|
(isDockerContainer ? 'redis://klz-redis:6379' : 'redis://localhost:6379');
|
|
|
|
// Only create a single instance in Node.js
|
|
const globalForRedis = global as unknown as { redis: Redis };
|
|
|
|
export const redis =
|
|
globalForRedis.redis ||
|
|
new Redis(redisUrl, {
|
|
maxRetriesPerRequest: 3,
|
|
});
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
globalForRedis.redis = redis;
|
|
}
|
|
|
|
export default redis;
|