This commit is contained in:
Liam 2022-10-21 10:30:41 +01:00
parent 79f221dbb5
commit 8793e81214

@ -9,10 +9,18 @@ const client = new Redis({
client.connect().catch(() => {}); client.connect().catch(() => {});
async function setValue(key, value, expireAt = 86400) { async function setValue(key, value, expireAt = 86400) {
if (client.status === "close" || client.status === "end") {
await client.connect().catch(() => {});
}
await client.set(key, value, "EX", expireAt); await client.set(key, value, "EX", expireAt);
} }
async function getValue(key) { async function getValue(key) {
if (client.status === "close" || client.status === "end") {
await client.connect().catch(() => {});
}
const yes = new Promise((reject, resolve) => { const yes = new Promise((reject, resolve) => {
client.get(key, (err, result) => { client.get(key, (err, result) => {
if (err !== null) { if (err !== null) {
@ -27,6 +35,10 @@ async function getValue(key) {
} }
async function exists(key) { async function exists(key) {
if (client.status === "close" || client.status === "end") {
await client.connect().catch(() => {});
}
const yes = new Promise((reject, resolve) => { const yes = new Promise((reject, resolve) => {
client.exists(key, (err, result) => { client.exists(key, (err, result) => {
if (err !== null) { if (err !== null) {