From 959589913350c7e190bb7e4a3f6fc22d8f411d93 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 24 Oct 2024 12:47:45 -0500 Subject: [PATCH] Updated the redis client to use dotenv to get the connection string. * Updated the redis client to trap bad connection strings with an error message. --- ving/cache.mjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ving/cache.mjs b/ving/cache.mjs index 14a7625b..ef3734c4 100644 --- a/ving/cache.mjs +++ b/ving/cache.mjs @@ -1,5 +1,8 @@ import Keyv from 'keyv'; import { ouch } from '#ving/utils/ouch.mjs'; +import 'dotenv/config'; +import '@keyv/redis'; + let cache = undefined; /** @@ -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;