From 5520840699434dd0e799a437158f4e538adb1ebb Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 24 Oct 2024 17:17:15 -0500 Subject: [PATCH] Updated cache to use which allows for cluster and allows us to reuse the existing redis client. --- ving/cache.mjs | 11 ++++------- ving/docs/change-log.md | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ving/cache.mjs b/ving/cache.mjs index 2f368b3f..238315f6 100644 --- a/ving/cache.mjs +++ b/ving/cache.mjs @@ -1,7 +1,7 @@ import Keyv from 'keyv'; import { ouch } from '#ving/utils/ouch.mjs'; -import '#ving/config.mjs'; -import '@keyv/redis'; +import { useRedis } from '#ving/redis.mjs'; +import { KeyvAnyRedis } from 'keyv-anyredis'; let cache = undefined; @@ -14,11 +14,8 @@ export const useCache = () => { return cache } const globalForKeyv = global; - const redisUrl = process.env.VING_REDIS || ''; - if (!redisUrl) { - throw new Error('VING_REDIS environment variable is not set'); - } - cache = globalForKeyv.keyv || new Keyv(redisUrl); + const store = new KeyvAnyRedis(useRedis()); + cache = globalForKeyv.keyv || new Keyv({ store }); if (process.env.NODE_ENV !== 'production') globalForKeyv.keyv = cache; diff --git a/ving/docs/change-log.md b/ving/docs/change-log.md index 8ed1ae7a..bb36de40 100644 --- a/ving/docs/change-log.md +++ b/ving/docs/change-log.md @@ -6,8 +6,7 @@ outline: deep ## October 2024 ### 2024-10-24 - * Using dotenv for environment variables. - * NOTE: You will need to run `npm i` to get the new modules. + * Installed dotenv for environment variables. * 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. * Updated the drizzle client to use dotenv to get the connection string. @@ -15,6 +14,9 @@ outline: deep * Fixed a potential bug where someone enters a negative page number into the paginator. * Fixed a bug in the Pager component introduced with the upgrade to PrimeVue 4 where the default page was 0 rather than 1. * Updated the redis client to allow for cluster. + * Installed keyv-anyredis for cache instead of @keyv/redis. + * Updated cache to use which allows for cluster and allows us to reuse the existing redis client. + * NOTE: You will need to run `npm i` to get the new modules. ### 2024-10-01 * Added colin's patch for mysql pagination.