All files / src/redis redis.config.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26      18x     81x                   8x 8x     8x 8x        
import { ConfigService } from "@nestjs/config";
import { RedisOptions } from "ioredis";
 
export const createRedisConfig = (
  configService: ConfigService,
): RedisOptions => {
  return {
    host: configService.get<string>("REDIS_HOST", "localhost"),
    port: configService.get<number>("REDIS_PORT", 6379),
    password: configService.get<string>("REDIS_PASSWORD"),
    db: configService.get<number>("REDIS_DB", 0),
    maxRetriesPerRequest: 3,
    lazyConnect: true,
    connectTimeout: 60000,
    commandTimeout: 5000,
    retryStrategy: (times: number) => {
      const delay = Math.min(times * 50, 2000);
      return delay;
    },
    reconnectOnError: (error: Error) => {
      const targetError = "READONLY";
      return error.message.includes(targetError);
    },
  };
};