From 90a930b5819d63adebb7e11a2c6d84369135ce31 Mon Sep 17 00:00:00 2001 From: Kristaps Fabians Geikins Date: Fri, 16 Feb 2024 11:40:11 +0200 Subject: [PATCH] fix(fe2): redis being initialized even without a valid connection string (#2046) --- .../frontend-2/plugins/004-redis.server.ts | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/frontend-2/plugins/004-redis.server.ts b/packages/frontend-2/plugins/004-redis.server.ts index 06ba3797a4..ecb34b4107 100644 --- a/packages/frontend-2/plugins/004-redis.server.ts +++ b/packages/frontend-2/plugins/004-redis.server.ts @@ -12,26 +12,28 @@ export default defineNuxtPlugin(async () => { const { redisUrl } = useRuntimeConfig() const logger = useLogger() - try { - const hasValidStatus = - redis && ['ready', 'connecting', 'reconnecting'].includes(redis.status) - if (!redis || !hasValidStatus) { - if (redis) { - await redis.quit() - } + if (redisUrl?.length) { + try { + const hasValidStatus = + redis && ['ready', 'connecting', 'reconnecting'].includes(redis.status) + if (!redis || !hasValidStatus) { + if (redis) { + await redis.quit() + } - redis = new Redis(redisUrl) + redis = new Redis(redisUrl) - redis.on('error', (err) => { - logger.error(err, 'Redis error') - }) + redis.on('error', (err) => { + logger.error(err, 'Redis error') + }) - redis.on('end', () => { - logger.info('Redis disconnected from server') - }) + redis.on('end', () => { + logger.info('Redis disconnected from server') + }) + } + } catch (e) { + logger.error(e, 'Redis setup failure') } - } catch (e) { - logger.error(e, 'Redis setup failure') } const isValid = redis && redis.status === 'ready'