|
@@ -1,3 +1,4 @@
|
|
|
+import async from "async";
|
|
|
import config from "config";
|
|
|
import redis from "redis";
|
|
|
import mongoose from "mongoose";
|
|
@@ -64,6 +65,15 @@ class _CacheModule extends CoreClass {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ // TODO move to a better place
|
|
|
+ CacheModule.runJob("KEYS", { pattern: "longJobs.*" }).then(keys => {
|
|
|
+ async.eachLimit(keys, 1, (key, next) => {
|
|
|
+ CacheModule.runJob("DEL", { key }).finally(() => {
|
|
|
+ next();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
this.client.on("error", err => {
|
|
|
if (this.getStatus() === "INITIALIZING") reject(err);
|
|
|
if (this.getStatus() === "LOCKDOWN") return;
|
|
@@ -409,6 +419,24 @@ class _CacheModule extends CoreClass {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Gets a list of keys in Redis with a matching pattern
|
|
|
+ *
|
|
|
+ * @param {object} payload - object containing payload
|
|
|
+ * @param {string} payload.pattern - pattern to search for
|
|
|
+ * @returns {Promise} - returns a promise (resolve, reject)
|
|
|
+ */
|
|
|
+ KEYS(payload) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const { pattern } = payload;
|
|
|
+
|
|
|
+ CacheModule.client.KEYS(pattern, (err, keys) => {
|
|
|
+ if (err) return reject(new Error(err));
|
|
|
+ return resolve(keys);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns a redis schema
|
|
|
*
|