Merge branch 'dev'

This commit is contained in:
Atridad Lahiji 2023-12-04 23:19:54 -07:00
commit 80774ed1d6
No known key found for this signature in database

View file

@ -1,22 +1,65 @@
import Redis from "ioredis";
export const cache = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
let cache: Redis | null = null;
let pub: Redis | null = null;
let sub: Redis | null = null;
export const pub = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
declare global {
var __cache: Redis | null;
var __pub: Redis | null;
var __sub: Redis | null;
}
export const sub = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
if (process.env.NODE_ENV === "production") {
cache = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
} else {
if (!global.__cache) {
global.__cache = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
}
cache = global.__cache;
}
if (process.env.NODE_ENV === "production") {
pub = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
} else {
if (!global.__pub) {
global.__pub = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
}
pub = global.__pub;
}
if (process.env.NODE_ENV === "production") {
sub = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
} else {
if (!global.__sub) {
global.__sub = process.env.REDIS_URL
? new Redis(process.env.REDIS_URL, {
family: 6,
})
: null;
}
sub = global.__sub;
}
export const publishToChannel = async (channel: string, message: string) => {
await pub?.publish(channel, JSON.stringify(message));