Open apedroferreira opened 2 years ago
I want to know this as well
I would love to get an example, since I have problems passing a valid RedisClient to publisher / subscriber prop. MAybe somebody can help me here out. I try to get it setup with NestJS
import { ConfigModule, ConfigService } from '@nestjs/config';
import { RedisPubSub } from 'graphql-redis-subscriptions';
import * as Redis from 'redis';
export const PUB_SUB = 'PUB_SUB';
@Global()
@Module({
imports: [ConfigModule],
providers: [
{
provide: 'PUB_SUB',
useFactory: (configService: ConfigService) => {
return new RedisPubSub({
publisher: Redis,
subscriber: Redis,
});
},
inject: [ConfigService],
},
],
exports: [PUB_SUB],
})
export class PubSubModule {}
I know I also have to pass host and port but I'm not sure how to pass the correct Class...
UPDATE: I managed it, please see as follows - Does anyone have concerns that it is not ok?
import { Global, Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { RedisPubSub } from 'graphql-redis-subscriptions';
import * as Redis from 'redis';
export const PUB_SUB = 'PUB_SUB';
@Global()
@Module({
imports: [ConfigModule],
providers: [
{
provide: 'PUB_SUB',
useFactory: async (configService: ConfigService) => {
const client = await Redis.createClient({
url:
configService.get<string>('NODE_ENV') === 'production'
? 'redis://redis:6379'
: 'redis://localhost:6379',
}).connect();
return new RedisPubSub({
publisher: client as any,
subscriber: client as any,
messageEventName: 'message_buffer',
pmessageEventName: 'pmessage_buffer',
});
},
inject: [ConfigService],
},
],
exports: [PUB_SUB],
})
export class PubSubModule {}
Does this library still support https://github.com/redis/node-redis? Doesn't seem to be working for v4 of node-redis.