Node.js / NestJS

Caching with Redis

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

20 pertanyaan wawancaraยท
Mid-Level
1

What is Redis in the context of caching?

Jawaban

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?

Jawaban

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?

Jawaban

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 pertanyaan wawancara

Kuasai Node.js / NestJS untuk wawancara berikutnya

Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.

Mulai gratis