diff --git a/README.md b/README.md index 86a8ebd..771d3b2 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,11 @@ With multi client ```typescript export default [ { - name:'test1', + clientName:'test1', url: 'redis://:authpassword@127.0.0.1:6380/4', }, { - name:'test2', + clientName:'test2', host: process.env.REDIS_HOST, port: parseInt(process.env.REDIS_PORT), db: parseInt(process.env.REDIS_DB), @@ -109,7 +109,7 @@ interface RedisOptions { /** * client name. default is a uuid, unique. */ - name?: string; + clientName?: string; url?: string; port?: number; host?: string; diff --git a/lib/redis-client.provider.ts b/lib/redis-client.provider.ts index 3eea84a..5f65d87 100644 --- a/lib/redis-client.provider.ts +++ b/lib/redis-client.provider.ts @@ -30,16 +30,16 @@ export const createClient = (): Provider => ({ if (Array.isArray(options)) { await Promise.all( options.map(async o => { - const key = o.name || defaultKey; + const key = o.clientName || defaultKey; if (clients.has(key)) { - throw new RedisClientError(`${o.name || 'default'} client is exists`); + throw new RedisClientError(`${o.clientName || 'default'} client is exists`); } clients.set(key, await getClient(o)); }), ); } else { - if (options.name && options.name.length !== 0) { - defaultKey = options.name; + if (options.clientName && options.clientName.length !== 0) { + defaultKey = options.clientName; } clients.set(defaultKey, await getClient(options)); } diff --git a/lib/redis.interface.ts b/lib/redis.interface.ts index a6d4db0..993a589 100644 --- a/lib/redis.interface.ts +++ b/lib/redis.interface.ts @@ -2,7 +2,7 @@ import { ModuleMetadata } from '@nestjs/common/interfaces'; import { Redis, RedisOptions } from 'ioredis'; export interface RedisModuleOptions extends RedisOptions { - name?: string; + clientName?: string; url?: string; onClientReady?(client: Redis): Promise; } diff --git a/lib/redis.service.ts b/lib/redis.service.ts index 4da6548..6e42c3a 100644 --- a/lib/redis.service.ts +++ b/lib/redis.service.ts @@ -9,14 +9,14 @@ export class RedisService { @Inject(REDIS_CLIENT) private readonly redisClient: RedisClient, ) {} - getClient(name?: string): Redis.Redis { - if (!name) { - name = this.redisClient.defaultKey; + getClient(clientName?: string): Redis.Redis { + if (!clientName) { + clientName = this.redisClient.defaultKey; } - if (!this.redisClient.clients.has(name)) { - throw new RedisClientError(`client ${name} does not exist`); + if (!this.redisClient.clients.has(clientName)) { + throw new RedisClientError(`client ${clientName} does not exist`); } - return this.redisClient.clients.get(name); + return this.redisClient.clients.get(clientName); } getClients(): Map {