Fix: Redis call chain #147

Merged
KevinMidboe merged 3 commits from fix/redis-call-chain into master 2022-09-25 11:39:49 +00:00
2 changed files with 21 additions and 16 deletions
Showing only changes of commit 0124a3c8bb - Show all commits

18
src/cache/redis.js vendored
View File

@@ -1,9 +1,9 @@
import redis from "redis";
import Configuration from "../config/configuration.js";
import redisMockClient from "./redisMock.js";
const configuration = Configuration.getInstance();
let client;
const mockCache = {};
try {
console.log("Trying to connect with redis.."); // eslint-disable-line no-console
@@ -20,21 +20,7 @@ try {
client.quit();
console.error("Unable to connect to redis, setting up redis-mock."); // eslint-disable-line no-console
client = {
get(key, callback) {
console.log(`redis-dummy get: ${key}`); // eslint-disable-line no-console
const hit = mockCache[key];
return Promise.resolve().then(callback(null, JSON.parse(hit)));
},
set(key, json, callback) {
console.log(`redis-dummy set: ${key}`); // eslint-disable-line no-console
mockCache[key] = JSON.stringify(json);
return Promise.resolve().then(callback(null, "OK"));
},
expire(key, TTL) {
console.log(`redis-dummy expire: ${key} with TTL ${TTL}`); // eslint-disable-line no-console
}
};
client = redisMockClient;
});
} catch (e) {}

19
src/cache/redisMock.js vendored Normal file
View File

@@ -0,0 +1,19 @@
const mockCache = {};
const redisMockClient = {
get(key, callback) {
// console.log(`redis-dummy get: ${key}`); // eslint-disable-line no-console
const hit = mockCache[key] || null;
return Promise.resolve(callback(null, hit));
},
set(key, json, callback) {
// console.log(`redis-dummy set: ${key}`); // eslint-disable-line no-console
mockCache[key] = JSON.stringify(json);
return Promise.resolve(callback(null, "OK"));
},
expire(key, TTL) {
// console.log(`redis-dummy expire: ${key} with TTL ${TTL}`); // eslint-disable-line no-console
}
};
export default redisMockClient;