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