This is the official NestJS documentation page for the Redis transporter in the microservices module. It describes how to use Redis as a message broker for inter-service communication using the publish/subscribe paradigm, with ioredis as the underlying driver.
Key takeaways
- The Redis transporter implements pub/sub messaging: messages are fire-and-forget with no delivery guarantee.
- Install
ioredisand configure viaTransport.REDISincreateMicroservice()orClientsModule.register(). - Supported options:
host,port,retryAttempts,retryDelay,wildcards. - Enable wildcards with the
wildcards: trueoption to usepsubscribe/pmessagefor pattern-based subscriptions (e.g.,@EventPattern('notifications.*')). - Access request context via
RedisContext(imported from@nestjs/microservices), exposinggetChannel(). - Subscribe to connection status via
client.statusstream: emitsconnected,disconnected,reconnecting. - Listen to internal Redis events with
client.on('error', ...)orserver.on<RedisEvents>('error', ...). - Access the underlying
ioredisdriver withunwrap(), which returns a tuple[pubClient, subClient]— one for publishing and one for subscribing.
Entities and concepts
Connections to existing knowledge
This is the authoritative source for Redis-based microservices in NestJS. It covers the messaging/broker use case, distinct from the caching use cases described in How to add Redis cache to a NestJS app and Using Redis Client in NestJS. The Transport.REDIS from @nestjs/microservices is unrelated to the CacheModule approach used for HTTP response caching. A separate copy of this same content exists under the title “NestJS - A progressive Node.js framework” (also from docs.nestjs.com).