From 8793e8121407f74d542c2db657b4ff19aa703448 Mon Sep 17 00:00:00 2001 From: Liam <67254223+RealFascinated@users.noreply.github.com> Date: Fri, 21 Oct 2022 10:30:41 +0100 Subject: [PATCH] part 2 --- src/utils/redisUtils.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utils/redisUtils.js b/src/utils/redisUtils.js index 512d3d3..c8747f0 100644 --- a/src/utils/redisUtils.js +++ b/src/utils/redisUtils.js @@ -9,10 +9,18 @@ const client = new Redis({ client.connect().catch(() => {}); 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); } async function getValue(key) { + if (client.status === "close" || client.status === "end") { + await client.connect().catch(() => {}); + } + const yes = new Promise((reject, resolve) => { client.get(key, (err, result) => { if (err !== null) { @@ -27,6 +35,10 @@ async function getValue(key) { } async function exists(key) { + if (client.status === "close" || client.status === "end") { + await client.connect().catch(() => {}); + } + const yes = new Promise((reject, resolve) => { client.exists(key, (err, result) => { if (err !== null) {