Zavedení podpory pro Redis, agnostické úložiště dat
This commit is contained in:
32
server/src/storage/redis.ts
Normal file
32
server/src/storage/redis.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { RedisClientType, createClient } from 'redis';
|
||||
import { StorageInterface } from "./StorageInterface";
|
||||
import { ClientData } from '../../../types';
|
||||
|
||||
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}` });
|
||||
client.connect();
|
||||
}
|
||||
|
||||
async hasData(date: string) {
|
||||
const data = await client.json.get(date);
|
||||
return (data ? true : false);
|
||||
}
|
||||
|
||||
async getData(date: string) {
|
||||
const data = await client.json.get(date, { path: '.' });
|
||||
return data as unknown as ClientData;
|
||||
}
|
||||
|
||||
async setData(date: string, data: ClientData) {
|
||||
await client.json.set(date, '.', data as any);
|
||||
const check = await client.json.get(date);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user