fix: redisPingAsync

This commit is contained in:
long2ice 2023-01-13 19:10:07 +08:00
parent db757123ba
commit 21cd4d64c3
1 changed files with 17 additions and 7 deletions

View File

@ -358,14 +358,24 @@ exports.radius = function (
* Redis server ping * Redis server ping
* @param {string} dsn The redis connection string * @param {string} dsn The redis connection string
*/ */
exports.redisPingAsync = async function (dsn) { exports.redisPingAsync = function (dsn) {
const client = redis.createClient({ return new Promise((resolve, reject) => {
url: dsn, 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;
}; };
/** /**