NestJS microservices use the Redis Transporter to enable publish/subscribe messaging between services via Redis channels.

Core concepts

  • Configured via Transport.REDIS from @nestjs/microservices.
  • Uses ioredis under the hood — each connection is a tuple of [publisher, subscriber] clients.
  • Messages are fire-and-forget: if no subscriber exists, the message is lost.
  • Supports wildcard subscriptions (psubscribe/pmessage) for pattern-based routing.

Message patterns

@MessagePattern('notifications')
handleMessage(@Payload() data: any, @Ctx() context: RedisContext) {}
 
@EventPattern('notifications.*')
handleEvent(@Payload() data: any) {}

Client creation

Via ClientsModule.register(), ClientProxyFactory.create(), or @Client() decorator.

Accessing internals

  • RedisContext.getChannel() — get the channel name in handlers
  • client.status — observable stream of connected/disconnected/reconnecting
  • client.on('error', ...) — listen to Redis driver events
  • unwrap() — access the underlying ioredis instances

Sources: NestJS Redis Microservices