Skip to content

Commit

Permalink
Updated the redis client to use dotenv to get the connection string.
Browse files Browse the repository at this point in the history
 * Updated the redis client to trap bad connection strings with an error message.
  • Loading branch information
rizen committed Oct 24, 2024
1 parent 209a764 commit 9595899
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ving/cache.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Keyv from 'keyv';
import { ouch } from '#ving/utils/ouch.mjs';
import 'dotenv/config';
import '@keyv/redis';

let cache = undefined;

/**
Expand All @@ -11,8 +14,11 @@ export const useCache = () => {
return cache
}
const globalForKeyv = global;

cache = globalForKeyv.keyv || new Keyv(process.env.VING_REDIS);
const redisUrl = process.env.VING_REDIS || '';
if (!redisUrl) {
throw new Error('VING_REDIS environment variable is not set');
}
cache = globalForKeyv.keyv || new Keyv(redisUrl);

if (process.env.NODE_ENV !== 'production')
globalForKeyv.keyv = cache;
Expand Down

0 comments on commit 9595899

Please sign in to comment.