refactor: commands from menu

This commit is contained in:
2023-08-04 13:48:12 +02:00
parent b95cfcc5b4
commit f9638c35fc
12 changed files with 317 additions and 114 deletions

24
lib/cache/cache.ts vendored
View File

@ -1,4 +1,5 @@
import {
Bulk,
connect,
Redis,
RedisConnectOptions,
@ -14,16 +15,31 @@ async function createCache<T>(): Promise<Map<string, T> | Redis> {
const conf: RedisConnectOptions = {
hostname: REDIS_HOST,
port: REDIS_PORT || 6379,
maxRetryCount: 2,
};
if (REDIS_PASS) {
conf.password = REDIS_PASS;
}
const client = await connect(conf);
console.log("[redis] connected");
return client;
try {
const client = await connect(conf);
console.log("[redis] connected");
return client;
} catch (_err) {
console.log("[cache] cant connect to redis, falling back to mock");
}
}
return new Map<string, T>();
const mockRedis = new Map<string, RedisValue>();
return {
async set(key: string, value: RedisValue) {
mockRedis.set(key, value);
return value.toString();
},
async get(key: string) {
return mockRedis.get(key) as Bulk;
},
};
}
const cache = await createCache();