partey_workadventure/back/src/Services/RedisClient.ts

25 lines
592 B
TypeScript
Raw Normal View History

import { ClientOpts, createClient, RedisClient } from "redis";
import { REDIS_HOST, REDIS_PASSWORD, REDIS_PORT } from "../Enum/EnvironmentVariable";
2021-11-08 17:44:44 +01:00
import log from "./Logger";
let redisClient: RedisClient | null = null;
if (REDIS_HOST !== undefined) {
const config: ClientOpts = {
host: REDIS_HOST,
port: REDIS_PORT,
};
if (REDIS_PASSWORD) {
config.password = REDIS_PASSWORD;
}
redisClient = createClient(config);
redisClient.on("error", (err) => {
2021-11-08 17:44:44 +01:00
log.error("Error connecting to Redis:", err);
});
}
export { redisClient };