Generalizace úložiště pro libovolná data

This commit is contained in:
2023-09-27 15:09:36 +02:00
parent 87beb5b66e
commit bef6178a6f
4 changed files with 24 additions and 26 deletions

View File

@@ -1,6 +1,5 @@
import { RedisClientType, createClient } from 'redis';
import { StorageInterface } from "./StorageInterface";
import { ClientData } from '../../../types';
let client: RedisClientType;
@@ -15,18 +14,18 @@ export default class RedisStorage implements StorageInterface {
client.connect();
}
async hasData(date: string) {
const data = await client.json.get(date);
async hasData(key: string) {
const data = await client.json.get(key);
return (data ? true : false);
}
async getData(date: string) {
const data = await client.json.get(date, { path: '.' });
return data as unknown as ClientData;
async getData<Type>(key: string) {
const data = await client.json.get(key, { path: '.' });
return data as Type;
}
async setData(date: string, data: ClientData) {
await client.json.set(date, '.', data as any);
const check = await client.json.get(date);
async setData<Type>(key: string, data: Type) {
await client.json.set(key, '.', data as any);
await client.json.get(key);
}
}