Skip to content

Commit

Permalink
refactor: make manager config public
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 23, 2024
1 parent db893ba commit 7f76177
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/redis_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ class RedisManager<ConnectionsList extends RedisConnectionsList> extends Emitter
this.#logger.fatal({ err: data.error }, 'Redis connection failure')
}.bind(this)

/**
* User provided config
*/
#config: {
connection: keyof ConnectionsList
connections: ConnectionsList
}

/**
* Reference to "import('ioredis').Redis.Command"
*/
Expand All @@ -91,11 +83,10 @@ class RedisManager<ConnectionsList extends RedisConnectionsList> extends Emitter
}

constructor(
config: { connection: keyof ConnectionsList; connections: ConnectionsList },
public managerConfig: { connection: keyof ConnectionsList; connections: ConnectionsList },
logger: Logger
) {
super()
this.#config = config
this.#logger = logger
}

Expand Down Expand Up @@ -126,7 +117,7 @@ class RedisManager<ConnectionsList extends RedisConnectionsList> extends Emitter
connection<ConnectionName extends keyof ConnectionsList>(
connectionName?: ConnectionName
): GetConnectionType<ConnectionsList, ConnectionName> {
const name = connectionName || this.#config.connection
const name = connectionName || this.managerConfig.connection
debug('resolving connection %s', name)

/**
Expand All @@ -140,7 +131,7 @@ class RedisManager<ConnectionsList extends RedisConnectionsList> extends Emitter
/**
* Get config for the named connection
*/
const config = this.#config.connections[name]
const config = this.managerConfig.connections[name]
if (!config) {
throw new RuntimeException(`Redis connection "${name.toString()}" is not defined`)
}
Expand Down Expand Up @@ -273,7 +264,7 @@ class RedisManager<ConnectionsList extends RedisConnectionsList> extends Emitter
* name is defined.
*/
async quit<ConnectionName extends keyof ConnectionsList>(name?: ConnectionName) {
const connection = this.activeConnections[name || this.#config.connection]
const connection = this.activeConnections[name || this.managerConfig.connection]
if (!connection) {
return
}
Expand All @@ -286,7 +277,7 @@ class RedisManager<ConnectionsList extends RedisConnectionsList> extends Emitter
* name is defined.
*/
async disconnect<ConnectionName extends keyof ConnectionsList>(name?: ConnectionName) {
const connection = this.activeConnections[name || this.#config.connection]
const connection = this.activeConnections[name || this.managerConfig.connection]
if (!connection) {
return
}
Expand Down

0 comments on commit 7f76177

Please sign in to comment.