0

I have a globally available Redis Module which creates a RedisCluster connection which I am importing in AppModule.

import { Module, Global } from '@nestjs/common';
import { Redis } from 'ioredis';

@Global()
@Module({
    providers: [{
        provide: 'REDIS_CONNECTION',
        useFactory: () => {
            return new Redis.Cluster([
                {
                    host: process.env?.REDIS_HOST,
                    port: process.env?.REDIS_PORT
                        ? Number(process.env?.REDIS_PORT)
                        : 6379,
                },
            ], {
                redisOptions: {
                    ...(process.env?.REDIS_PASSWORD && {
                        password: process.env.REDIS_PASSWORD,
                    }),
                    maxRetriesPerRequest: null,
                    enableReadyCheck: false,
                },
            });
        }

    }],
    exports: ['REDIS_CONNECTION'],
})
export class RedisModule { }

I have another module named QueueModule where I need to set up the config for bull but am unsure how to inject the same globally available RedisCluster connection

@Module({
  imports: [
    BullModule.forRootAsync({
       **// how to inject connection here?**
    }),
  ],
  providers: [QueueProducerService, QueueConsumerService, Logger],
  exports: [QueueProducerService],
})
export class QueueModule {}

0 Answers0