* chore(): Move peer deps into a single package and re export from framework * WIP * update core packages * update cli and deps * update medusa * update exports path * remove analyze * update modules deps * finalise changes * fix yarn * fix import * Refactor peer dependencies into a single package Consolidate peer dependencies into one package and re-export from the framework. * update changeset * Update .changeset/brown-cows-sleep.md Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * rm deps * fix deps * increase timeout * upgrade version * update versions * update versions * fixes * update lock * fix missing import * fix missing import --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
38 lines
997 B
TypeScript
38 lines
997 B
TypeScript
import { LoaderOptions } from "@medusajs/framework/types"
|
|
import { asValue } from "@medusajs/framework/awilix"
|
|
import Redis from "ioredis"
|
|
import { RedisCacheModuleOptions } from "../types"
|
|
|
|
export default async ({
|
|
container,
|
|
logger,
|
|
options,
|
|
}: LoaderOptions): Promise<void> => {
|
|
const { redisUrl, redisOptions } = options as RedisCacheModuleOptions
|
|
|
|
if (!redisUrl) {
|
|
throw Error(
|
|
"No `redisUrl` provided in `cacheService` module options. It is required for the Redis Cache Module."
|
|
)
|
|
}
|
|
|
|
const connection = new Redis(redisUrl, {
|
|
// Lazy connect to properly handle connection errors
|
|
lazyConnect: true,
|
|
...(redisOptions ?? {}),
|
|
})
|
|
|
|
try {
|
|
await connection.connect()
|
|
logger?.info(`Connection to Redis in module 'cache-redis' established`)
|
|
} catch (err) {
|
|
logger?.error(
|
|
`An error occurred while connecting to Redis in module 'cache-redis': ${err}`
|
|
)
|
|
}
|
|
|
|
container.register({
|
|
cacheRedisConnection: asValue(connection),
|
|
})
|
|
}
|