mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Add BaseRedisRepository as parent class of RedisNotificationRepository.ts and RedisParkingRepository.ts
This commit is contained in:
@@ -1,45 +1,17 @@
|
||||
import { createClient } from 'redis';
|
||||
import { ParkingGetterSetterRepository } from "./ParkingGetterSetterRepository";
|
||||
import { IParkingStructure, IParkingStructureTimestampRecord } from "../entities/ParkingRepositoryEntities";
|
||||
import { HistoricalParkingAverageQueryResult, ParkingStructureCountOptions } from "./ParkingGetterRepository";
|
||||
import { BaseRedisRepository } from "./BaseRedisRepository";
|
||||
|
||||
export type ParkingStructureID = string;
|
||||
|
||||
// Every 10 minutes
|
||||
export const PARKING_LOGGING_INTERVAL_MS = 600000;
|
||||
|
||||
export class RedisParkingRepository implements ParkingGetterSetterRepository {
|
||||
export class RedisParkingRepository extends BaseRedisRepository implements ParkingGetterSetterRepository {
|
||||
private dataLastAdded: Map<ParkingStructureID, Date> = new Map();
|
||||
private loggingIntervalMs = PARKING_LOGGING_INTERVAL_MS;
|
||||
|
||||
constructor(
|
||||
private redisClient = createClient({
|
||||
url: process.env.REDIS_URL,
|
||||
socket: {
|
||||
tls: (process.env.REDIS_URL?.match(/rediss:/) != null),
|
||||
rejectUnauthorized: false,
|
||||
}
|
||||
}),
|
||||
) {
|
||||
}
|
||||
|
||||
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();
|
||||
this.dataLastAdded.clear();
|
||||
}
|
||||
|
||||
addOrUpdateParkingStructure = async (structure: IParkingStructure): Promise<void> => {
|
||||
// Store current structure data
|
||||
await this.redisClient.hSet(`parking:structure:${structure.id}`, {
|
||||
|
||||
Reference in New Issue
Block a user