Node.js / NestJS

Caching with Redis

Cache manager, Redis integration, cache strategies, TTL, invalidation, distributed cache

20 pytań z rozmów·
Mid-Level
1

What is Redis in the context of caching?

Odpowiedź

Redis (Remote Dictionary Server) is an in-memory key-value NoSQL database primarily used as a distributed cache. Unlike traditional disk-based databases, Redis stores data in RAM which provides millisecond response times. It supports advanced data structures like strings, hashes, lists, sets and sorted sets, making it highly flexible for different caching patterns.

2

Which npm package should be installed to integrate Redis in NestJS?

Odpowiedź

To integrate Redis in NestJS, you need to install @nestjs/cache-manager and cache-manager-redis-store (or cache-manager-redis-yet for recent versions). The @nestjs/cache-manager package provides the official CacheModule that integrates with NestJS dependency injection system. The cache-manager-redis-store package enables using Redis as the cache backend instead of the default in-memory cache.

3

Which method to use for configuring CacheModule with Redis globally?

Odpowiedź

The CacheModule.register() method configures cache locally for a module, while CacheModule.registerAsync() with isGlobal: true makes it available globally throughout the application. The async approach allows injecting ConfigService to dynamically retrieve the Redis URL from environment variables. Using isGlobal avoids reimporting CacheModule in every application module.

4

What is TTL (Time To Live) in the Redis cache context?

5

What is the purpose of the @UseInterceptors(CacheInterceptor) decorator in NestJS?

+17 pytań z rozmów

Opanuj Node.js / NestJS na następną rozmowę

Uzyskaj dostęp do wszystkich pytań, flashcards, testów technicznych, ćwiczeń code review i symulatorów rozmów.

Zacznij za darmo