Redis in NestJS: A Production-First Guide from Real Projects

Redis in NestJS: A Production-First Guide from Real Projects

Written by
Written by

Rohit K.

Post Date
Post Date

Jan 28, 2026

shares

 

What Redis Really Means in a NestJS Backend

Why Redis Is Used (The Real Problems It Solves)

When You Should (and Should Not) Use Redis

Introduce Redis When:

Avoid Redis When:

Premature Redis usage creates more bugs than it solves.

Redis for Queue Jobs in NestJS (Where It Truly Shines)

Why Redis Works So Well for Background Jobs

Common Real-World Use Cases

The Architecture Pattern That Actually Works

NestJS Queue Setup (BullMQ Example)

// redis.config.ts export const redisConfig = { connection: { host: process.env.REDIS_HOST, port: Number(process.env.REDIS_PORT), password: process.env.REDIS_PASSWORD, }, };
// queue.module.ts import { BullModule } from '@nestjs/bullmq'; BullModule.registerQueue({ name: 'email-queue', ...redisConfig, });
@Injectable() export class EmailService { constructor( @InjectQueue('email-queue') private queue: Queue, ) {} async sendWelcomeEmail(userId: number) { await this.queue.add( 'send-welcome', { userId }, { attempts: 3, backoff: { type: 'exponential', delay: 5000 }, }, ); } }
@Processor('email-queue') export class EmailProcessor { @Process('send-welcome') async handle(job: Job<{ userId: number }>) { // call email provider // handle failures carefully } }

Redis for Caching (Global Cache Only)

Why Global Cache Wins

Global Cache Setup

// app.module.ts CacheModule.register({ isGlobal: true, store: redisStore, host: process.env.REDIS_HOST, port: Number(process.env.REDIS_PORT), ttl: 60, // default TTL });

Real-Life Cache Example

@Injectable() export class ConfigService { constructor(@Inject(CACHE_MANAGER) private cache: Cache) {} async getAppConfig() { const cached = await this.cache.get('app-config'); if (cached) return cached; const config = await this.fetchFromDB(); await this.cache.set('app-config', config, 300); return config; } }

What You Should Cache

What You Should Not Cache

Production-Ready Considerations (Hard-Learned Lessons)

For Queue Jobs

For Caching

Redis Operations

Final Thoughts

Redis isn’t magic.

If this resonated with you, we’d love to hear your take or see you visit us along for more.