Unverified 提交 e6959bd4 authored 作者: ziyun.zhu's avatar ziyun.zhu 提交者: GitHub

Merge pull request #41 from teralad/master

fix: client name ignored while creating single client.
...@@ -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,6 +48,9 @@ exports.createClient = () => ({ ...@@ -48,6 +48,9 @@ exports.createClient = () => ({
}))); })));
} }
else { else {
if (options.name && options.name.length !== 0) {
defaultKey = options.name;
}
clients.set(defaultKey, yield getClient(options)); clients.set(defaultKey, yield getClient(options));
} }
return { return {
......
...@@ -24,7 +24,7 @@ let RedisService = class RedisService { ...@@ -24,7 +24,7 @@ let RedisService = class RedisService {
name = this.redisClient.defaultKey; name = this.redisClient.defaultKey;
} }
if (!this.redisClient.clients.has(name)) { if (!this.redisClient.clients.has(name)) {
throw new redis_client_provider_1.RedisClientError(`client ${name} is not exists`); throw new redis_client_provider_1.RedisClientError(`client ${name} does not exist`);
} }
return this.redisClient.clients.get(name); return this.redisClient.clients.get(name);
} }
......
...@@ -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,6 +38,9 @@ export const createClient = (): Provider => ({ ...@@ -38,6 +38,9 @@ export const createClient = (): Provider => ({
}), }),
); );
} else { } else {
if (options.name && options.name.length !== 0) {
defaultKey = options.name;
}
clients.set(defaultKey, await getClient(options)); clients.set(defaultKey, await getClient(options));
} }
......
...@@ -14,7 +14,7 @@ export class RedisService { ...@@ -14,7 +14,7 @@ export class RedisService {
name = this.redisClient.defaultKey; name = this.redisClient.defaultKey;
} }
if (!this.redisClient.clients.has(name)) { if (!this.redisClient.clients.has(name)) {
throw new RedisClientError(`client ${name} is not exists`); throw new RedisClientError(`client ${name} does not exist`);
} }
return this.redisClient.clients.get(name); return this.redisClient.clients.get(name);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论