Refactored permissions check. Updated redis lib.

This commit is contained in:
Mike Cao 2022-12-01 10:58:50 -08:00
parent 1a7369e1f6
commit a4e80ca3e5
5 changed files with 58 additions and 15 deletions

View file

@ -3,16 +3,18 @@ import debug from 'debug';
const log = debug('umami:redis');
const REDIS = Symbol();
const DELETED = 'DELETED';
let redis;
const enabled = Boolean(process.env.REDIS_URL);
const url = process.env.REDIS_URL;
const enabled = Boolean(url);
async function getClient() {
if (!process.env.REDIS_URL) {
if (!enabled) {
return null;
}
const client = createClient({ url: process.env.REDIS_URL });
const client = createClient({ url });
client.on('error', err => log(err));
await client.connect();
@ -59,4 +61,4 @@ async function connect() {
return redis;
}
export default { enabled, client: redis, log, connect, get, set, del };
export default { enabled, client: redis, log, connect, get, set, del, DELETED };