fix: more economical use of redis clients
This commit is contained in:
@@ -58,6 +58,7 @@
|
||||
"express-session": "^1.17.1",
|
||||
"fs-exists-cached": "^1.0.0",
|
||||
"glob": "^7.1.6",
|
||||
"ioredis": "^4.17.3",
|
||||
"joi-objectid": "^3.0.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"medusa-core-utils": "^1.0.0-alpha.30",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Bull from "bull"
|
||||
import Redis from "ioredis"
|
||||
import config from "../config"
|
||||
/**
|
||||
* Can keep track of multiple subscribers to different events and run the
|
||||
@@ -19,8 +20,25 @@ class EventBusService {
|
||||
/** @private {BullQueue} used for cron jobs */
|
||||
this.cronQueue_ = new Bull(`cron-jobs:queue`, config.redisURI)
|
||||
|
||||
// Economical way of dealing with redis clients
|
||||
const client = new Redis(config.redisURI)
|
||||
const subscriber = new Redis(config.redisURI)
|
||||
|
||||
const opts = {
|
||||
createClient: type => {
|
||||
switch (type) {
|
||||
case "client":
|
||||
return client
|
||||
case "subscriber":
|
||||
return subscriber
|
||||
default:
|
||||
throw new Error("Unknown type: ", type)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/** @private {BullQueue} */
|
||||
this.queue_ = new Bull(`${this.constructor.name}:queue`, config.redisURI)
|
||||
this.queue_ = new Bull(`${this.constructor.name}:queue`, opts)
|
||||
|
||||
// Register our worker to handle emit calls
|
||||
this.queue_.process(this.worker_)
|
||||
|
||||
@@ -3478,6 +3478,21 @@ ioredis@^4.14.1:
|
||||
redis-parser "^3.0.0"
|
||||
standard-as-callback "^2.0.1"
|
||||
|
||||
ioredis@^4.17.3:
|
||||
version "4.17.3"
|
||||
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.17.3.tgz#9938c60e4ca685f75326337177bdc2e73ae9c9dc"
|
||||
integrity sha512-iRvq4BOYzNFkDnSyhx7cmJNOi1x/HWYe+A4VXHBu4qpwJaGT1Mp+D2bVGJntH9K/Z/GeOM/Nprb8gB3bmitz1Q==
|
||||
dependencies:
|
||||
cluster-key-slot "^1.1.0"
|
||||
debug "^4.1.1"
|
||||
denque "^1.1.0"
|
||||
lodash.defaults "^4.2.0"
|
||||
lodash.flatten "^4.4.0"
|
||||
redis-commands "1.5.0"
|
||||
redis-errors "^1.2.0"
|
||||
redis-parser "^3.0.0"
|
||||
standard-as-callback "^2.0.1"
|
||||
|
||||
ip-regex@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9"
|
||||
|
||||
Reference in New Issue
Block a user