API 参考 / @142vip/redis / RedisConfig
接口: RedisConfig
定义于: packages/redis/src/core/redis.interface.ts:33
Redis 建立连接配置
theme_extends
RedisClientConfig.Partial<RedisClusterConfig>
属性
autoPipeliningIgnoredCommands?
optionalautoPipeliningIgnoredCommands:string[]
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:132
默认值
[]继承自
RedisClientConfig.autoPipeliningIgnoredCommands
autoResendUnfulfilledCommands?
optionalautoResendUnfulfilledCommands:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:65
Whether or not to resend unfulfilled commands on reconnect. Unfulfilled commands are most likely to be blocking commands such as brpop or blpop.
默认值
true继承自
RedisClientConfig.autoResendUnfulfilledCommands
autoResubscribe?
optionalautoResubscribe:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:59
When the client reconnects, channels subscribed in the previous connection will be resubscribed automatically if autoResubscribe is true.
默认值
true继承自
RedisClientConfig.autoResubscribe
clusterNodes?
optionalclusterNodes:ClusterNode[]
定义于: packages/redis/src/core/redis.interface.ts:26
继承自
RedisClusterConfig.clusterNodes
clusterOptions?
optionalclusterOptions:ClusterOptions
定义于: packages/redis/src/core/redis.interface.ts:27
继承自
RedisClusterConfig.clusterOptions
commandQueue?
optionalcommandQueue:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:134
继承自
RedisClientConfig.commandQueue
commandTimeout?
optionalcommandTimeout:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:13
If a command does not return a reply within a set number of milliseconds, a "Command timed out" error will be thrown.
继承自
RedisClientConfig.commandTimeout
connectionName?
optionalconnectionName:string
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:38
Set the name of the connection to make it easier to identity the connection in client list.
链接
https://redis.io/commands/client-setname
继承自
RedisClientConfig.connectionName
Connector?
optionalConnector:ConnectorConstructor
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:7
继承自
connectTimeout?
optionalconnectTimeout:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:102
How long the client will wait before killing a socket due to inactivity during initial connection.
默认值
10000继承自
RedisClientConfig.connectTimeout
db?
optionaldb:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:53
Database index to use.
默认值
0继承自
disconnectTimeout?
optionaldisconnectTimeout:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:41
继承自
RedisClientConfig.disconnectTimeout
enableAutoPipelining?
optionalenableAutoPipelining:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:128
默认值
false继承自
RedisClientConfig.enableAutoPipelining
enableOfflineQueue?
optionalenableOfflineQueue:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:145
By default, if the connection to Redis server has not been established, 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.
默认值
true继承自
RedisClientConfig.enableOfflineQueue
enableReadyCheck?
optionalenableReadyCheck:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:153
The client will sent an INFO command to check whether the server is still loading data from the disk ( which happens when the server is just launched) when the connection is established, and only wait until the loading process is finished before emitting the ready event.
默认值
true继承自
RedisClientConfig.enableReadyCheck
enableTLSForSentinelMode?
optionalenableTLSForSentinelMode:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:43
继承自
RedisClientConfig.enableTLSForSentinelMode
failoverDetector?
optionalfailoverDetector:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:51
继承自
RedisClientConfig.failoverDetector
family?
optionalfamily:number
定义于: node_modules/.pnpm/@types+node@22.10.7/node_modules/@types/node/net.d.ts:55
继承自
host?
optionalhost:string
定义于: node_modules/.pnpm/@types+node@22.10.7/node_modules/@types/node/net.d.ts:51
继承自
keepAlive?
optionalkeepAlive:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:26
Enable/disable keep-alive functionality.
链接
https://nodejs.org/api/net.html#socketsetkeepaliveenable-initialdelay
默认值
0继承自
keyPrefix?
optionalkeyPrefix:string
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/utils/Commander.d.ts:5
继承自
lazyConnect?
optionallazyConnect:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:161
When a Redis instance is initialized, a connection to the server is immediately established. Set this to true will delay the connection to the server until the first command is sent or redis.connect() is called explicitly.
默认值
false继承自
maxLoadingRetryTime?
optionalmaxLoadingRetryTime:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:124
默认值
10000继承自
RedisClientConfig.maxLoadingRetryTime
maxRetriesPerRequest?
optionalmaxRetriesPerRequest:null|number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:120
The commands that don't get a reply due to the connection to the server is lost are put into a queue and will be resent on reconnect (if allowed by the retryStrategy option). This option is used to configure how many reconnection attempts should be allowed before the queue is flushed with a MaxRetriesPerRequestError error. Set this options to null instead of a number to let commands wait forever until the connection is alive again.
默认值
20继承自
RedisClientConfig.maxRetriesPerRequest
monitor?
optionalmonitor:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:109
This option is used internally when you call redis.monitor() to tell Redis to enter the monitor mode when the connection is established.
默认值
false继承自
name?
optionalname:string
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:28
Master group name of the Sentinel
继承自
natMap?
optionalnatMap:NatMap
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:45
继承自
noDelay?
optionalnoDelay:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:32
Enable/disable the use of Nagle's algorithm.
链接
https://nodejs.org/api/net.html#socketsetnodelaynodelay
默认值
true继承自
offlineQueue?
optionalofflineQueue:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:133
继承自
RedisClientConfig.offlineQueue
password?
optionalpassword:string
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:47
If set, client will send AUTH command with the value of this option when connected.
继承自
path?
optionalpath:string
定义于: node_modules/.pnpm/@types+node@22.10.7/node_modules/@types/node/net.d.ts:70
继承自
port?
optionalport:number
定义于: node_modules/.pnpm/@types+node@22.10.7/node_modules/@types/node/net.d.ts:50
继承自
preferredSlaves?
optionalpreferredSlaves:PreferredSlaves
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:39
继承自
RedisClientConfig.preferredSlaves
readOnly?
optionalreadOnly:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:91
默认值
false继承自
reconnectOnError?
optionalreconnectOnError:null|ReconnectOnError
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:87
Whether or not to reconnect on certain Redis errors. This options by default is null, which means it should never reconnect on Redis errors. You can pass a function that accepts an Redis error, and returns:
trueor1to trigger a reconnection.falseor0to not reconnect.2to reconnect and resend the failed command (who triggered the error) after reconnection.
示例
const redis = new Redis({
reconnectOnError(err) {
const targetError = 'READONLY'
if (err.message.includes(targetError)) {
// Only reconnect when the error contains "READONLY"
return true // or `return 1;`
}
},
})默认值
null继承自
RedisClientConfig.reconnectOnError
retryStrategy()?
optionalretryStrategy: (times) =>null|number|void
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:8
参数
times
number
返回
null | number | void
继承自
RedisClientConfig.retryStrategy
role?
optionalrole:"master"|"slave"
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:32
默认值
'master'继承自
scripts?
optionalscripts:Record<string, {lua:string;numberOfKeys?:number;readOnly?:boolean; }>
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:165
默认值
undefined继承自
sentinelCommandTimeout?
optionalsentinelCommandTimeout:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:42
继承自
RedisClientConfig.sentinelCommandTimeout
sentinelMaxConnections?
optionalsentinelMaxConnections:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:50
默认值
10继承自
RedisClientConfig.sentinelMaxConnections
sentinelPassword?
optionalsentinelPassword:string
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:35
继承自
RedisClientConfig.sentinelPassword
sentinelReconnectStrategy()?
optionalsentinelReconnectStrategy: (retryAttempts) =>null|number|void
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:38
参数
retryAttempts
number
返回
null | number | void
继承自
RedisClientConfig.sentinelReconnectStrategy
sentinelRetryStrategy()?
optionalsentinelRetryStrategy: (retryAttempts) =>null|number|void
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:37
参数
retryAttempts
number
返回
null | number | void
继承自
RedisClientConfig.sentinelRetryStrategy
sentinels?
optionalsentinels:Partial<SentinelAddress>[]
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:36
继承自
sentinelTLS?
optionalsentinelTLS:ConnectionOptions
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:44
继承自
sentinelUsername?
optionalsentinelUsername:string
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:34
继承自
RedisClientConfig.sentinelUsername
showFriendlyErrorStack?
optionalshowFriendlyErrorStack:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/utils/Commander.d.ts:6
继承自
RedisClientConfig.showFriendlyErrorStack
socketTimeout?
optionalsocketTimeout:number
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:20
If the socket does not receive data within a set number of milliseconds:
- the socket is considered "dead" and will be destroyed
- the client will reject any running commands (altought they might have been processed by the server)
- the reconnect strategy will kick in (depending on the configuration)
继承自
RedisClientConfig.socketTimeout
stringNumbers?
optionalstringNumbers:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:97
When enabled, numbers returned by Redis will be converted to JavaScript strings instead of numbers. This is necessary if you want to handle big numbers (above Number.MAX_SAFE_INTEGER === 2^53).
默认值
false继承自
RedisClientConfig.stringNumbers
tls?
optionaltls:ConnectionOptions
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:33
继承自
updateSentinels?
optionalupdateSentinels:boolean
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/connectors/SentinelConnector/index.d.ts:46
继承自
RedisClientConfig.updateSentinels
url?
optionalurl:string
定义于: packages/redis/src/core/redis.interface.ts:19
继承自
username?
optionalusername:string
定义于: node_modules/.pnpm/ioredis@5.6.0/node_modules/ioredis/built/redis/RedisOptions.d.ts:43
If set, client will send AUTH command with the value of this option as the first argument when connected. This is supported since Redis 6.
