2021-07-19 15:57:50 +02:00
|
|
|
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";
|
2021-07-19 15:57:50 +02:00
|
|
|
|
|
|
|
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);
|
2021-07-19 15:57:50 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export { redisClient };
|