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

Node Redis Support #547

Open
apedroferreira opened this issue Oct 3, 2022 · 2 comments
Open

Node Redis Support #547

apedroferreira opened this issue Oct 3, 2022 · 2 comments

Comments

@apedroferreira
Copy link

Does this library still support https://github.com/redis/node-redis?
Doesn't seem to be working for v4 of node-redis.

@mabecth
Copy link

mabecth commented Nov 8, 2022

I want to know this as well

@Maetes
Copy link

Maetes commented Mar 20, 2023

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 {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants