Zavedení podpory pro Redis, agnostické úložiště dat
This commit is contained in:
19
server/src/storage/index.ts
Normal file
19
server/src/storage/index.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user