add redis status/min

This commit is contained in:
Michael C
2021-12-30 16:47:11 -05:00
parent ceabeefe21
commit b9a620fc3b
3 changed files with 38 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ interface RedisSB {
setAsync?(key: string, value: string): Promise<{err: Error | null, reply: string | null}>;
delAsync?(...keys: [string]): Promise<Error | null>;
close?(flush?: boolean): void;
increment?(key: string): Promise<{err: Error| null, replies: any[] | null}>;
}
let exportObject: RedisSB = {
@@ -20,6 +21,8 @@ let exportObject: RedisSB = {
new Promise((resolve) => resolve({ err: null, reply: undefined })),
delAsync: () =>
new Promise((resolve) => resolve(null)),
increment: () =>
new Promise((resolve) => resolve({ err: null, replies: undefined })),
};
if (config.redis) {
@@ -31,7 +34,12 @@ if (config.redis) {
exportObject.setAsync = (key, value) => new Promise((resolve) => client.set(key, value, (err, reply) => resolve({ err, reply })));
exportObject.delAsync = (...keys) => new Promise((resolve) => client.del(keys, (err) => resolve(err)));
exportObject.close = (flush) => client.end(flush);
exportObject.increment = (key) => new Promise((resolve) =>
client.multi()
.incr(key)
.expire(key, 60)
.exec((err, replies) => resolve({ err, replies }))
);
client.on("error", function(error) {
Logger.error(error);
});