Interface RedisOptions


  • RedisOptions


autoResendUnfulfilledCommands?: boolean

If true, client will resend unfulfilled commands(e.g. block commands) in the previous connection when reconnected. default: true.

autoResubscribe?: boolean

After reconnected, if the previous connection was in the subscriber mode, client will auto re-subscribe these channels. default: true.

commandTimeout?: number

The milliseconds before a timeout occurs when executing a single command. By default, there is no timeout and the client will wait indefinitely. The timeout is enforced only on the client side, not server side. The server may still complete the operation after a timeout error occurs on the client side.

connectTimeout?: number

The milliseconds before a timeout occurs during the initial connection to the Redis server. default: 10000.

connectionName?: string
db?: number

Database index to use.

disconnectTimeout?: number

The milliseconds before socket.destroy() is called after socket.end() if the connection remains half-open during disconnection. default: 2000

dropBufferSupport?: boolean

If you are using the hiredis parser, it's highly recommended to enable this option. Create another instance with dropBufferSupport disabled for other commands that you want to return binary instead of string

enableAutoPipelining?: boolean

When enabled, all commands issued during an event loop iteration are automatically wrapped in a pipeline and sent to the server at the same time. This can improve performance by 30-50%. default: false.

enableOfflineQueue?: boolean

By default, if there is no active connection to the Redis server, commands are added to a queue and are executed once the connection is "ready" (when enableReadyCheck is true, "ready" means the Redis server has loaded the database from disk, otherwise means the connection to the Redis server has been established). If this option is false, when execute the command when the connection isn't ready, an error will be returned.

enableReadyCheck?: boolean

When a connection is established to the Redis server, the server might still be loading the database from disk. While loading, the server not respond to any commands. To work around this, when this option is true, ioredis will check the status of the Redis server, and when the Redis server is able to process commands, a ready event will be emitted.

enableTLSForSentinelMode?: boolean

Whether to support the tls option when connecting to Redis via sentinel mode. default: false.

family?: number

4 (IPv4) or 6 (IPv6), Defaults to 4.

host?: string
keepAlive?: number

TCP KeepAlive on the socket with a X ms delay before start. Set to a non-number value to disable keepAlive.

keyPrefix?: string
lazyConnect?: boolean
maxRetriesPerRequest?: null | number

By default, all pending commands will be flushed with an error every 20 retry attempts. That makes sure commands won't wait forever when the connection is down. You can change this behavior by setting maxRetriesPerRequest.

Set maxRetriesPerRequest to null to disable this behavior, and every command will wait forever until the connection is alive again (which is the default behavior before ioredis v4).

maxScriptsCachingTime?: number

Default script definition caching time.

name?: string

default: null.

natMap?: NatMap

NAT map for sentinel connector. default: null.

noDelay?: boolean

Whether to disable the Nagle's Algorithm.

password?: string

If set, client will send AUTH command with the value of this option when connected.

path?: string

Local domain socket path. If set the port, host and family will be ignored.

port?: number
preferredSlaves?: PreferredSlaves

Can be used to prefer a particular slave or set of slaves based on priority.

readOnly?: boolean

Enable READONLY mode for the connection. Only available for cluster mode. default: false.

role?: "master" | "slave"

default: "master".

sentinelPassword?: string
sentinelTLS?: SecureContextOptions
sentinelUsername?: string
sentinels?: {
    host: string;
    port: number;
showFriendlyErrorStack?: boolean

Whether to show a friendly error stack. Will decrease the performance significantly.

stringNumbers?: boolean

Force numbers to be always returned as JavaScript strings. This option is necessary when dealing with big numbers (exceed the [-2^53, +2^53] range).

tls?: ConnectionOptions
updateSentinels?: boolean

Update the given sentinels list with new IP addresses when communicating with existing sentinels. default: true.

username?: string

If set, client will send AUTH command with the value of this option as the first argument when connected. The password option must be set too. Username should only be set for Redis >=6.


  • 1/true means reconnect, 2 means reconnect and resend failed command. Returning false will ignore the error and do nothing.


    • error: Error

    Returns boolean | 2 | 1

  • When the return value isn't a number, ioredis will stop trying to reconnect. Fixed in:


    • times: number

    Returns null | number | void

  • If sentinelRetryStrategy returns a valid delay time, ioredis will try to reconnect from scratch. default: function(times) { return Math.min(times * 10, 1000); }


    • times: number

    Returns null | number | void