Zavedení podpory pro Redis, agnostické úložiště dat

This commit is contained in:
2023-08-06 17:46:51 +02:00
parent 8a75c98c9a
commit 37542499a9
11 changed files with 282 additions and 97 deletions

View File

@@ -0,0 +1,19 @@
import { StorageInterface } from "./StorageInterface";
import JsonStorage from "./json";
import RedisStorage from "./redis";
const JSON_KEY = 'json';
const REDIS_KEY = 'redis';
let storage: StorageInterface;
if (!process.env.STORAGE || process.env.STORAGE?.toLowerCase() === JSON_KEY) {
storage = new JsonStorage();
} else if (process.env.STORAGE?.toLowerCase() === REDIS_KEY) {
storage = new RedisStorage();
} else {
throw Error("Nepodporovaná hodnota proměnné STORAGE: " + process.env.STORAGE + ", podporované jsou 'json' nebo 'redis'");
}
export default function getStorage(): StorageInterface {
return storage;
}