Skip to content

IORedisOptions

reference
1 min readUpdated

Kind: Interface

Source: packages/microservices/external/redis.interface.ts

Part of: Microservices

IORedisOptions defines the Redis client connection and behavior options used by the microservices Redis integration. It configures authentication, database selection, TCP settings, command timeouts, client identification, and reconnect behavior for an ioredis-compatible connector.

Properties

PropertyType
Connectorany
retryStrategy`(times: number) => number
commandTimeoutnumber
keepAlivenumber
noDelayboolean
connectionNamestring
clientInfoTagstring
usernamestring
passwordstring
dbnumber
autoResubscribeboolean
autoResendUnfulfilledCommandsboolean
reconnectOnError`((err: Error) => boolean
readOnlyboolean
stringNumbersboolean
connectTimeoutnumber
monitorboolean
maxRetriesPerRequest`number
maxLoadingRetryTimenumber
enableAutoPipeliningboolean
autoPipeliningIgnoredCommandsstring[]
offlineQueueboolean
commandQueueboolean
enableOfflineQueueboolean
enableReadyCheckboolean
lazyConnectboolean
scriptsRecord< string, { lua: string; numberOfKeys?: number; readOnly?: boolean } >
keyPrefixstring
showFriendlyErrorStackboolean
disconnectTimeoutnumber
tlsConnectionOptions
namestring
role`'master'
sentinelUsernamestring
sentinelPasswordstring
sentinelsArray<Partial<any>>
sentinelRetryStrategy`(retryAttempts: number) => number
sentinelReconnectStrategy`(retryAttempts: number) => number
preferredSlavesany
sentinelCommandTimeoutnumber
enableTLSForSentinelModeboolean
sentinelTLSConnectionOptions
natMapany
updateSentinelsboolean
sentinelMaxConnectionsnumber
failoverDetectorboolean

Diagram

mermaid
graph LR
  App[Microservice] --> Options[IORedisOptions]
  Options --> Connector[Connector]
  Options --> Auth[username / password]
  Options --> Database[db]
  Options --> Network[keepAlive / noDelay]
  Options --> Retry[retryStrategy]
  Options --> Timeout[commandTimeout]
  Options --> Identity[connectionName / clientInfoTag]
  Connector --> Redis[(Redis Server)]

Usage

ts
import type { IORedisOptions } from './redis.interface';
import Redis from 'ioredis';

const redisOptions: IORedisOptions = {
  Connector: Redis,
  host: 'localhost',
  port: 6379,
  username: 'default',
  password: process.env.REDIS_PASSWORD,
  db: 0,

  connectionName: 'orders-service',
  clientInfoTag: 'orders-worker',

  commandTimeout: 5_000,
  keepAlive: 10_000,
  noDelay: true,

  retryStrategy: (times) => {
    if (times > 10) {
      return null; // Stop retrying after 10 attempts.
    }

    return Math.min(times * 200, 2_000);
  },
};

AI Coding Instructions

  • Provide an ioredis-compatible constructor through Connector; ensure it supports the configured connection options.
  • Keep credentials in environment variables or a secrets manager rather than hardcoding username or password.
  • Return a delay in milliseconds from retryStrategy; return null or void when reconnect attempts should stop.
  • Use distinct connectionName and clientInfoTag values per service to simplify Redis monitoring and debugging.
  • Configure commandTimeout, keepAlive, and noDelay according to the deployment network and service latency requirements.

Was this page helpful?

Download as PDF
IORedisOptions — NestJS head-to-head