mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-18 00:10:32 +00:00
Add BaseRedisRepository as parent class of RedisNotificationRepository.ts and RedisParkingRepository.ts
This commit is contained in:
33
src/repositories/BaseRedisRepository.ts
Normal file
33
src/repositories/BaseRedisRepository.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createClient } from 'redis';
|
||||
|
||||
export abstract class BaseRedisRepository {
|
||||
protected redisClient;
|
||||
|
||||
constructor(
|
||||
redisClient = createClient({
|
||||
url: process.env.REDIS_URL,
|
||||
socket: {
|
||||
tls: (process.env.REDIS_URL?.match(/rediss:/) != null),
|
||||
rejectUnauthorized: false,
|
||||
}
|
||||
}),
|
||||
) {
|
||||
this.redisClient = redisClient;
|
||||
}
|
||||
|
||||
get isReady() {
|
||||
return this.redisClient.isReady;
|
||||
}
|
||||
|
||||
public async connect() {
|
||||
await this.redisClient.connect();
|
||||
}
|
||||
|
||||
public async disconnect() {
|
||||
await this.redisClient.disconnect();
|
||||
}
|
||||
|
||||
public async clearAllData() {
|
||||
await this.redisClient.flushAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user