Skip to content

Commit

Permalink
fix(fe2): redis being initialized even without a valid connection str…
Browse files Browse the repository at this point in the history
…ing (#2046)
  • Loading branch information
fabis94 authored Feb 16, 2024
1 parent fef908f commit 90a930b
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/frontend-2/plugins/004-redis.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 90a930b

Please sign in to comment.