NestJS microservices use the Redis Transporter to enable publish/subscribe messaging between services via Redis channels.
Core concepts
- Configured via
Transport.REDISfrom@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 handlersclient.status— observable stream ofconnected/disconnected/reconnectingclient.on('error', ...)— listen to Redis driver eventsunwrap()— access the underlying ioredis instances
Sources: NestJS Redis Microservices