提交 2d00f67c authored 作者: Varun Kumaar's avatar Varun Kumaar

refactor: assign name to RedisClient if name is given

上级 5e27f90f
...@@ -37,7 +37,7 @@ exports.createClient = () => ({ ...@@ -37,7 +37,7 @@ exports.createClient = () => ({
provide: redis_constants_1.REDIS_CLIENT, provide: redis_constants_1.REDIS_CLIENT,
useFactory: (options) => __awaiter(this, void 0, void 0, function* () { useFactory: (options) => __awaiter(this, void 0, void 0, function* () {
const clients = new Map(); const clients = new Map();
const defaultKey = uuid(); let defaultKey = uuid();
if (Array.isArray(options)) { if (Array.isArray(options)) {
yield Promise.all(options.map((o) => __awaiter(this, void 0, void 0, function* () { yield Promise.all(options.map((o) => __awaiter(this, void 0, void 0, function* () {
const key = o.name || defaultKey; const key = o.name || defaultKey;
...@@ -48,7 +48,10 @@ exports.createClient = () => ({ ...@@ -48,7 +48,10 @@ exports.createClient = () => ({
}))); })));
} }
else { else {
clients.set(options.name || defaultKey, yield getClient(options)); if (options.name.length !== 0) {
defaultKey = options.name;
}
clients.set(defaultKey, yield getClient(options));
} }
return { return {
defaultKey, defaultKey,
......
...@@ -25,7 +25,7 @@ export const createClient = (): Provider => ({ ...@@ -25,7 +25,7 @@ export const createClient = (): Provider => ({
provide: REDIS_CLIENT, provide: REDIS_CLIENT,
useFactory: async (options: RedisModuleOptions | RedisModuleOptions[]): Promise<RedisClient> => { useFactory: async (options: RedisModuleOptions | RedisModuleOptions[]): Promise<RedisClient> => {
const clients = new Map<string, Redis.Redis>(); const clients = new Map<string, Redis.Redis>();
const defaultKey = uuid(); let defaultKey = uuid();
if (Array.isArray(options)) { if (Array.isArray(options)) {
await Promise.all( await Promise.all(
...@@ -38,7 +38,10 @@ export const createClient = (): Provider => ({ ...@@ -38,7 +38,10 @@ export const createClient = (): Provider => ({
}), }),
); );
} else { } else {
clients.set(options.name || defaultKey, await getClient(options)); if (options.name.length !== 0) {
defaultKey = options.name;
}
clients.set(defaultKey, await getClient(options));
} }
return { return {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论