-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis.decorator.ts
More file actions
26 lines (23 loc) · 950 Bytes
/
Copy pathredis.decorator.ts
File metadata and controls
26 lines (23 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { applyDecorators } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '../configs/config.service';
export const prefixesForRedisClients: string[] = new Array<string>();
export function RedisServer(prefix: string = '') {
console.log('RedisServer', prefix);
if (!prefixesForRedisClients.includes(prefix)) {
prefixesForRedisClients.push(prefix);
}
return Inject(`RedisService${prefix}`);
}
// This function now expects a ConfigService instance to be passed in
export function RedisServers(configService: ConfigService) {
const configRedisServers = configService.get('REDIS_SERVERS');
const decorators = [];
if (configRedisServers && typeof configRedisServers === 'object') {
for (const key in configRedisServers) {
decorators.push(Inject(`REDIS_${key}_CLIENT`));
}
}
//console.log('decorators', decorators);
return applyDecorators(...decorators);
}