Skip to content

Commit 46a886d

Browse files
committed
๐Ÿš‘ !HOTFIX: redis pub/sub์€ ๋‹ค๋ฅธ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์šฉํ•˜๋„๋ก ๋ณ€๊ฒฝ
1 parent c3cf551 commit 46a886d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

โ€ŽBE/src/common/redis/redis.domain-service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import Redis from 'ioredis';
44
@Injectable()
55
export class RedisDomainService {
66
constructor(
7-
@Inject('REDIS_CLIENT')
8-
private readonly redis: Redis,
7+
@Inject('REDIS_CLIENT') private readonly redis: Redis,
8+
@Inject('REDIS_PUBLISHER') private readonly publisher: Redis,
9+
@Inject('REDIS_SUBSCRIBER') private readonly subscriber: Redis,
910
) {}
1011

1112
async exists(key: string): Promise<number> {
@@ -64,11 +65,11 @@ export class RedisDomainService {
6465
}
6566

6667
async publish(channel: string, message: string) {
67-
return this.redis.publish(channel, message);
68+
return this.publisher.publish(channel, message);
6869
}
6970

7071
async subscribe(channel: string) {
71-
await this.redis.subscribe(channel);
72+
await this.subscriber.subscribe(channel);
7273
}
7374

7475
on(callback: (message: string) => void) {

โ€ŽBE/src/common/redis/redis.module.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ import { RedisDomainService } from './redis.domain-service';
1515
});
1616
},
1717
},
18+
{
19+
provide: 'REDIS_PUBLISHER',
20+
useFactory: () => {
21+
return new Redis({
22+
host: process.env.REDIS_HOST || 'redis',
23+
port: Number(process.env.REDIS_PORT || 6379),
24+
});
25+
},
26+
},
27+
{
28+
provide: 'REDIS_SUBSCRIBER',
29+
useFactory: () => {
30+
return new Redis({
31+
host: process.env.REDIS_HOST || 'redis',
32+
port: Number(process.env.REDIS_PORT || 6379),
33+
});
34+
},
35+
},
1836
RedisDomainService,
1937
],
2038
exports: [RedisDomainService, 'REDIS_CLIENT'],

0 commit comments

Comments
ย (0)