0
0
NestJSframework~20 mins

Redis transport in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Transport Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output when a NestJS microservice using Redis transport receives a message?

Consider a NestJS microservice configured with Redis transport that listens for a message pattern 'sum'. The handler adds two numbers from the data and returns the result.

What will be the response when the client sends {a: 5, b: 7}?

NestJS
import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';

@Controller()
export class MathController {
  @MessagePattern('sum')
  sum(data: {a: number; b: number}): number {
    return data.a + data.b;
  }
}
ANaN
B12
Cundefined
D57
Attempts:
2 left
💡 Hint

Think about what the sum function returns when given two numbers.

📝 Syntax
intermediate
2:00remaining
Which option correctly configures a NestJS microservice to use Redis transport?

Choose the correct way to create a NestJS microservice using Redis transport on port 6379.

NestJS
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Transport } from '@nestjs/microservices';

async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, {
    transport: Transport.REDIS,
    options: {
      host: 'localhost',
      port: 6379,
    },
  });
  await app.listen();
}
bootstrap();
Atransport: Transport.REDIS, options: { host: 'localhost', port: 6379 }
Btransport: 'redis', options: { url: 'redis://localhost:6379' }
Ctransport: Transport.REDIS, options: { url: 'redis://localhost:6379' }
Dtransport: Transport.TCP, options: { host: 'localhost', port: 6379 }
Attempts:
2 left
💡 Hint

NestJS Redis transport supports host and port in options.

🔧 Debug
advanced
2:00remaining
Why does this NestJS Redis microservice fail to connect?

Given the following microservice bootstrap code, why does the connection to Redis fail?

NestJS
const app = await NestFactory.createMicroservice(AppModule, {
  transport: Transport.REDIS,
  options: {
    host: '127.0.0.1',
    port: 6380,
  },
});
await app.listen();
ATransport.REDIS does not accept 'host' and 'port' options, only 'url'.
BThe host '127.0.0.1' is invalid for Redis connections.
CRedis server is not running on port 6380, causing connection failure.
DMissing await before app.listen() causes the failure.
Attempts:
2 left
💡 Hint

Check if Redis is running on the specified port.

state_output
advanced
2:00remaining
What is the value of 'response' after sending a message to a Redis microservice?

In a NestJS client, a message with pattern 'multiply' is sent with data {x: 3, y: 4}. The microservice multiplies these numbers and returns the result.

What is the value of 'response' after awaiting the send call?

NestJS
const client = app.connectMicroservice({
  transport: Transport.REDIS,
  options: { url: 'redis://localhost:6379' },
});

await client.connect();
const response = await client.send('multiply', { x: 3, y: 4 }).toPromise();
A12
B7
C{x: 3, y: 4}
Dundefined
Attempts:
2 left
💡 Hint

Think about what the microservice returns for the 'multiply' pattern.

🧠 Conceptual
expert
2:00remaining
Which statement about Redis transport in NestJS microservices is TRUE?

Choose the correct statement about using Redis transport in NestJS microservices.

ARedis transport does not support pattern-based message routing.
BRedis transport requires manual handling of message serialization and deserialization by the developer.
CRedis transport can only be used for event-based fire-and-forget messaging, not request-response.
DRedis transport supports request-response messaging patterns with automatic message serialization.
Attempts:
2 left
💡 Hint

Consider how NestJS microservices handle messaging with Redis transport.