@azteam/redis-async
Version:
N/A
39 lines (34 loc) • 1.02 kB
JavaScript
import RedisAsync from './RedisAsync';
class Provider {
constructor(configs = []) {
this.connections = {};
this.configs = {};
if (Array.isArray(configs)) {
configs.map((config) => {
this.configs[config.name] = config;
return true;
});
} else {
this.configs.main = configs;
}
}
getConnection(name = 'main') {
if (!this.connections[name]) {
if (this.configs[name]) {
this.connections[name] = new RedisAsync(this.configs[name]);
} else {
return this.getConnection('main');
}
}
return this.connections[name];
}
async waitAllConnection() {
await Promise.all(
Object.keys(this.configs).map((keyConfig) => {
const connection = this.getConnection(keyConfig);
return connection.waitConnection();
})
);
}
}
export default Provider;