Files
speckle-server/packages/frontend-2/plugins/004-redis.server.ts
T
Kristaps Fabians Geikins 83d8035dc2 chore: upgrade to eslint 9 (#2348)
* root + server

* frontend

* frontend-2

* dui3

* dui3

* tailwind theme

* ui-components

* preview service

* viewer

* viewer-sandbox

* fileimport-service

* webhook service

* objectloader

* shared

* ui-components-nuxt

* WIP full config

* WIP full linter

* eslint projectwide util

* minor fix

* removing redundant ci

* clean up test errors

* fixed prettier formatting

* CI improvements

* TSC lint fix

* 'buildBatch' needs to be async since some batch types (like Text) require it. Removed a disabled liniting rule from ObjLoader

* removed unnecessary void

---------

Co-authored-by: AlexandruPopovici <alexandrupopoviciioan@gmail.com>
2024-06-12 14:38:02 +03:00

36 lines
800 B
TypeScript

import type { Redis } from 'ioredis'
import { createRedis } from '~/lib/core/helpers/redis'
/**
* Re-using the same client for all SSR reqs (shouldn't be a problem)
*/
let redis: InstanceType<typeof Redis> | undefined = undefined
/**
* Provide redis (only in SSR)
*/
export default defineNuxtPlugin(async () => {
const logger = useLogger()
try {
const hasValidStatus =
redis && ['ready', 'connecting', 'reconnecting'].includes(redis.status)
if (!redis || !hasValidStatus) {
if (redis) {
await redis.quit()
}
redis = await createRedis({ logger })
}
} catch (e) {
logger.error(e, 'Redis setup failure')
}
const isValid = redis && redis.status === 'ready'
return {
provide: {
redis: isValid ? redis : undefined
}
}
})