Generalizace úložiště pro libovolná data
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user