Files
speckle-server/packages/frontend-2/plugins/040-redis.server.ts
T
Kristaps Fabians Geikins a6a4ceee86 feat: true-myth result structures & other auth policy improvements (#4262)
* fixing up typing

* better dynamic loader mechanism

* buildReqLoaders cleanup

* added caching to loaders

* ensuring all loaders are async

* fe2 plugins error handling fix

* feat(shared): true-myth result structures & other auth policy improvements

* moving workspaceCore loaders to correct place
2025-03-25 17:49:02 +01: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
}
}
})