jormungandr-bite/packages/backend/src/db/redis.ts
ThatOneCalculator f5c7b6f55f feat: cache server
2023-07-06 11:50:34 -07:00

24 lines
563 B
TypeScript

import Redis from "ioredis";
import config from "@/config/index.js";
export function createConnection() {
let source = config.redis;
if (config.cacheServer) {
source = config.cacheServer;
}
return new Redis({
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,
});
}
export const subscriber = createConnection();
subscriber.subscribe(config.host);
export const redisClient = createConnection();