Martin Berka 52769fc981
All checks were successful
ci/woodpecker/push/workflow Pipeline was successful
Opravy dle SonarQube
2025-08-07 13:12:55 +02:00

34 lines
938 B
TypeScript

import { RedisClientType, createClient } from 'redis';
import { StorageInterface } from "./StorageInterface";
let client: RedisClientType;
/**
* Implementace úložiště využívající Redis server.
*/
export default class RedisStorage implements StorageInterface {
constructor() {
const HOST = process.env.REDIS_HOST ?? 'localhost';
const PORT = process.env.REDIS_PORT ?? 6379;
client = createClient({ url: `redis://${HOST}:${PORT}` });
}
async initialize() {
client.connect();
}
async hasData(key: string) {
const data = await client.json.get(key);
return (!!data);
}
async getData<Type>(key: string) {
const data = await client.json.get(key, { path: '.' });
return data as Type;
}
async setData<Type>(key: string, data: Type) {
await client.json.set(key, '.', data as any);
await client.json.get(key);
}
}