mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 17:00:30 +00:00
37 lines
868 B
TypeScript
37 lines
868 B
TypeScript
import { createClient, RedisClientType } from 'redis';
|
|
import { REDIS_RECONNECT_INTERVAL } from "../environment";
|
|
import { EventEmitter } from 'stream';
|
|
|
|
export abstract class BaseRedisRepository extends EventEmitter {
|
|
protected redisClient;
|
|
|
|
constructor(
|
|
redisClient: RedisClientType = createClient({
|
|
url: process.env.REDIS_URL,
|
|
socket: {
|
|
tls: process.env.NODE_ENV === 'production',
|
|
rejectUnauthorized: false,
|
|
reconnectStrategy: REDIS_RECONNECT_INTERVAL,
|
|
},
|
|
}),
|
|
) {
|
|
super();
|
|
this.redisClient = redisClient;
|
|
this.redisClient.on('error', (err) => {
|
|
console.error(err.stack);
|
|
});
|
|
}
|
|
|
|
get isReady() {
|
|
return this.redisClient.isReady;
|
|
}
|
|
|
|
public async connect() {
|
|
await this.redisClient.connect();
|
|
}
|
|
|
|
public async disconnect() {
|
|
await this.redisClient.disconnect();
|
|
}
|
|
}
|