2023-11-26 21:33:46 +01:00
|
|
|
import Redis from "ioredis";
|
2023-12-05 08:12:10 +01:00
|
|
|
import config from "@/config/index.js";
|
2016-12-28 23:49:51 +01:00
|
|
|
|
2021-03-23 06:54:09 +01:00
|
|
|
export function createConnection() {
|
2023-07-06 20:50:34 +02:00
|
|
|
let source = config.redis;
|
|
|
|
if (config.cacheServer) {
|
|
|
|
source = config.cacheServer;
|
|
|
|
}
|
2022-06-24 12:22:19 +02:00
|
|
|
return new Redis({
|
2023-07-06 20:50:34 +02:00
|
|
|
port: source.port,
|
|
|
|
host: source.host,
|
|
|
|
family: source.family ?? 0,
|
|
|
|
password: source.pass,
|
|
|
|
username: source.user ?? "default",
|
|
|
|
keyPrefix: `${source.prefix}:`,
|
|
|
|
db: source.db || 0,
|
|
|
|
tls: source.tls,
|
2022-06-24 12:22:19 +02:00
|
|
|
});
|
2021-03-23 06:54:09 +01:00
|
|
|
}
|
2021-03-23 03:53:25 +01:00
|
|
|
|
2022-08-04 10:20:48 +02:00
|
|
|
export const subscriber = createConnection();
|
|
|
|
subscriber.subscribe(config.host);
|
2021-03-23 03:53:25 +01:00
|
|
|
|
2021-03-23 06:54:09 +01:00
|
|
|
export const redisClient = createConnection();
|