The Redis Transporter is a NestJS microservice transport layer that uses Redis pub/sub for inter-service messaging. Messages are published to channels and received by subscribed microservices.
How it works
- Configured via
Transport.REDISincreateMicroservice()orClientsModule.register(). - Uses ioredis under the hood — each client maintains two connections: one for publishing, one for subscribing.
- Messages are fire-and-forget — if no subscriber exists, the message is discarded.
Key features
- Wildcards: Enable pattern-based subscriptions with
wildcards: trueand patterns like'notifications.*'. - Context: Access channel info via
RedisContext.getChannel()in message handlers. - Status stream: Subscribe to
client.statusforconnected,disconnected,reconnectingevents. - Internal events: Listen to Redis events (
'error', etc.) viaclient.on()orserver.on<RedisEvents>(). - Underlying driver: Access the ioredis instances via
unwrap<[Redis, Redis]>(), returning[pubClient, subClient].
Contrast with caching use
The Redis Transporter is for messaging between services, not for caching. It is configured via @nestjs/microservices, not @nestjs/common’s CacheModule.