feat(medusa): add redis_prefix in configModule.projectConfig (#4268)

This commit is contained in:
Derek Wene
2023-06-14 09:24:35 -05:00
committed by GitHub
parent ca477c86af
commit 81dfeb43ea
4 changed files with 17 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
feat(medusa): add ability to prefix all redis cache keys in project config

View File

@@ -41,7 +41,10 @@ export default async ({ app, configModule }: Options): Promise<Express> => {
if (configModule?.projectConfig?.redis_url) {
const RedisStore = createStore(session)
const redisClient = redis.createClient(configModule.projectConfig.redis_url)
sessionOpts.store = new RedisStore({ client: redisClient })
sessionOpts.store = new RedisStore({
client: redisClient,
prefix: `${configModule?.projectConfig?.redis_prefix ?? ""}sess:`,
})
}
app.set("trust proxy", 1)

View File

@@ -30,6 +30,10 @@ export default class JobSchedulerService {
this.config_ = config
this.logger_ = logger
const prefix = `${config?.projectConfig?.redis_prefix ?? ""}${
this.constructor.name
}`
if (singleton && config?.projectConfig?.redis_url) {
// Required config
// See: https://github.com/OptimalBits/bull/blob/develop/CHANGELOG.md#breaking-changes
@@ -40,13 +44,13 @@ export default class JobSchedulerService {
this.queue_ = new Queue(`scheduled-jobs:queue`, {
connection,
prefix: `${this.constructor.name}`,
prefix,
})
// Register scheduled job worker
new Worker("scheduled-jobs:queue", this.scheduledJobsWorker, {
connection,
prefix: `${this.constructor.name}`,
prefix,
})
}
}

View File

@@ -23,6 +23,7 @@ export type HttpCompressionOptions = {
export type ProjectConfigOptions = {
redis_url?: string
redis_prefix?: string
redis_options?: RedisOptions
session_options?: SessionOptions
@@ -35,7 +36,7 @@ export type ProjectConfigOptions = {
database_schema?: string
database_logging: LoggerOptions
// @deprecated - only postgres is supported, so this config has no effect
// @deprecated - only postgres is supported, so this config has no effect
database_type?: string
http_compression?: HttpCompressionOptions