Tweak to constructor logic

master
j 2024-03-23 01:11:56 -04:00
parent ba477cdbdb
commit 9863078fd9
1 changed files with 11 additions and 4 deletions

View File

@ -1,19 +1,26 @@
import Redis from 'ioredis'; import Redis, { RedisOptions } from 'ioredis';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
dotenv.config(); dotenv.config();
interface RedisConfig extends RedisOptions {
host: string;
port: number;
password?: string;
}
class RedisSessionManager { class RedisSessionManager {
private static instance: RedisSessionManager; private static instance: RedisSessionManager;
public readonly client: Redis; public readonly client: Redis;
private constructor() { private constructor() {
this.client = new Redis({ const redisConfig: RedisConfig = {
host: process.env.REDIS_HOST, host: process.env.REDIS_HOST!,
port: Number(process.env.REDIS_PORT), port: Number(process.env.REDIS_PORT),
password: process.env.REDIS_PASSWORD || undefined, password: process.env.REDIS_PASSWORD || undefined,
showFriendlyErrorStack: true, showFriendlyErrorStack: true,
}); };
this.client = new Redis(redisConfig);
} }
public static getInstance(): RedisSessionManager { public static getInstance(): RedisSessionManager {