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;