Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -109,7 +109,7 @@ interface RedisOptions {
/**
* client name. default is a uuid, unique.
*/
name?: string;
clientName?: string;
url?: string;
port?: number;
host?: string;
Expand Down
8 changes: 4 additions & 4 deletions lib/redis-client.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/redis.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Redis.Redis> {
Expand Down