Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 54: rename name -> clientName so we can use sentinel #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -74,11 +74,11 @@ With multi client
```typescript
export default [
{
name:'test1',
clientName:'test1',
url: 'redis://:[email protected]: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;
8 changes: 4 additions & 4 deletions lib/redis-client.provider.ts
Original file line number Diff line number Diff line change
@@ -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));
}
2 changes: 1 addition & 1 deletion lib/redis.interface.ts
Original file line number Diff line number Diff line change
@@ -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>;
}
12 changes: 6 additions & 6 deletions lib/redis.service.ts
Original file line number Diff line number Diff line change
@@ -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> {