From 21cd4d64c353b528bac115a6175664983b0112d2 Mon Sep 17 00:00:00 2001 From: long2ice Date: Fri, 13 Jan 2023 19:10:07 +0800 Subject: [PATCH] fix: redisPingAsync --- server/util-server.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index f3d01b10e..c443f859a 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -358,14 +358,24 @@ exports.radius = function ( * Redis server ping * @param {string} dsn The redis connection string */ -exports.redisPingAsync = async function (dsn) { - const client = redis.createClient({ - url: dsn, +exports.redisPingAsync = function (dsn) { + return new Promise((resolve, reject) => { + const client = redis.createClient({ + url: dsn, + }); + client.on("error", (err) => { + reject(err); + }); + client.connect().then(() => { + client.ping().then((res, err) => { + if (err) { + reject(err); + } else { + resolve(res); + } + }); + }); }); - await client.connect(); - const pong = await client.ping(); - await client.disconnect(); - return pong; }; /**