Add BaseRedisRepository as parent class of RedisNotificationRepository.ts and RedisParkingRepository.ts

This commit is contained in:
2025-07-02 20:00:44 -04:00
parent 19336ce6ec
commit 53632fe470
3 changed files with 56 additions and 85 deletions

View File

@@ -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}`, {