🧬 Advanced

Redis & Caching Patterns

Redis usage for caching, session storage, and job queues in Ever Gauzy.

Overview

Redis is used for several purposes in Gauzy:

Use CaseDescription
CachingAPI response and query caching
Job QueuesBullMQ background job processing
Session StorageDistributed session management
Real-timeSocket.IO adapter for multi-instance

Configuration

VariableDescriptionDefault
REDIS_HOSTRedis hostlocalhost
REDIS_PORTRedis port6379
REDIS_PASSWORDRedis password—
REDIS_TLSEnable TLSfalse

BullMQ Job Queues

Background jobs are processed using BullMQ with Redis:

import { InjectQueue } from "@nestjs/bull";

@Injectable()
export class MyService {
  constructor(@InjectQueue("email") private emailQueue: Queue) {}

  async sendEmail(data: EmailData) {
    await this.emailQueue.add("send", data, {
      attempts: 3,
      backoff: { type: "exponential", delay: 1000 },
    });
  }
}

Cache Patterns

API Response Caching

@Get('/expensive-query')
@UseInterceptors(CacheInterceptor)
@CacheTTL(300) // 5 minutes
async getExpensiveData() { ... }

Manual Cache Management

@Injectable()
export class MyService {
  constructor(@Inject(CACHE_MANAGER) private cache: Cache) {}

  async getData(key: string) {
    const cached = await this.cache.get(key);
    if (cached) return cached;

    const data = await this.fetchFromDB();
    await this.cache.set(key, data, { ttl: 300 });
    return data;
  }
}

Edit this page

Copyright © 2023-Present Ever Co. LTD.Docs by Sourcey