Tweak to constructor logic
parent
ba477cdbdb
commit
9863078fd9
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue