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