mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 21:00:58 +03:00
Fix: Add keep-alive options to Redis clients to prevent idle timeouts and socket closing. (#4377)
* redis keepalive mechanism for all redis * removed offline queue commands * Simplified changes for consistency. Added REDIS_KEEP_ALIVE env variable. * update redis socket alive env variable * lint fix --------- Co-authored-by: Henry <hzj94@hotmail.com> Co-authored-by: Henry Heng <henryheng@flowiseai.com>
This commit is contained in:
+10
-1
@@ -126,10 +126,19 @@ const getRedisClient = async (nodeData: INodeData, options: ICommonObject) => {
|
||||
host,
|
||||
username,
|
||||
password,
|
||||
keepAlive:
|
||||
process.env.REDIS_KEEP_ALIVE && !isNaN(parseInt(process.env.REDIS_KEEP_ALIVE, 10))
|
||||
? parseInt(process.env.REDIS_KEEP_ALIVE, 10)
|
||||
: undefined,
|
||||
...tlsOptions
|
||||
})
|
||||
} else {
|
||||
client = new Redis(redisUrl)
|
||||
client = new Redis(redisUrl, {
|
||||
keepAlive:
|
||||
process.env.REDIS_KEEP_ALIVE && !isNaN(parseInt(process.env.REDIS_KEEP_ALIVE, 10))
|
||||
? parseInt(process.env.REDIS_KEEP_ALIVE, 10)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
|
||||
return client
|
||||
|
||||
@@ -83,10 +83,19 @@ class RedisEmbeddingsCache implements INode {
|
||||
host,
|
||||
username,
|
||||
password,
|
||||
keepAlive:
|
||||
process.env.REDIS_KEEP_ALIVE && !isNaN(parseInt(process.env.REDIS_KEEP_ALIVE, 10))
|
||||
? parseInt(process.env.REDIS_KEEP_ALIVE, 10)
|
||||
: undefined,
|
||||
...tlsOptions
|
||||
})
|
||||
} else {
|
||||
client = new Redis(redisUrl)
|
||||
client = new Redis(redisUrl, {
|
||||
keepAlive:
|
||||
process.env.REDIS_KEEP_ALIVE && !isNaN(parseInt(process.env.REDIS_KEEP_ALIVE, 10))
|
||||
? parseInt(process.env.REDIS_KEEP_ALIVE, 10)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
|
||||
ttl ??= '3600'
|
||||
|
||||
@@ -132,7 +132,21 @@ class BufferMemoryExtended extends FlowiseMemory implements MemoryMethods {
|
||||
}
|
||||
|
||||
private async withRedisClient<T>(fn: (client: Redis) => Promise<T>): Promise<T> {
|
||||
const client = typeof this.redisOptions === 'string' ? new Redis(this.redisOptions) : new Redis(this.redisOptions)
|
||||
const client =
|
||||
typeof this.redisOptions === 'string'
|
||||
? new Redis(this.redisOptions, {
|
||||
keepAlive:
|
||||
process.env.REDIS_KEEP_ALIVE && !isNaN(parseInt(process.env.REDIS_KEEP_ALIVE, 10))
|
||||
? parseInt(process.env.REDIS_KEEP_ALIVE, 10)
|
||||
: undefined
|
||||
})
|
||||
: new Redis({
|
||||
...this.redisOptions,
|
||||
keepAlive:
|
||||
process.env.REDIS_KEEP_ALIVE && !isNaN(parseInt(process.env.REDIS_KEEP_ALIVE, 10))
|
||||
? parseInt(process.env.REDIS_KEEP_ALIVE, 10)
|
||||
: undefined
|
||||
})
|
||||
try {
|
||||
return await fn(client)
|
||||
} finally {
|
||||
|
||||
@@ -147,7 +147,15 @@ class Redis_VectorStores implements INode {
|
||||
}
|
||||
|
||||
try {
|
||||
const redisClient = createClient({ url: redisUrl })
|
||||
const redisClient = createClient({
|
||||
url: redisUrl,
|
||||
socket: {
|
||||
keepAlive:
|
||||
process.env.REDIS_KEEP_ALIVE && !isNaN(parseInt(process.env.REDIS_KEEP_ALIVE, 10))
|
||||
? parseInt(process.env.REDIS_KEEP_ALIVE, 10)
|
||||
: undefined // milliseconds
|
||||
}
|
||||
})
|
||||
await redisClient.connect()
|
||||
|
||||
const storeConfig: RedisVectorStoreConfig = {
|
||||
@@ -212,7 +220,15 @@ class Redis_VectorStores implements INode {
|
||||
redisUrl = 'redis://' + username + ':' + password + '@' + host + ':' + portStr
|
||||
}
|
||||
|
||||
const redisClient = createClient({ url: redisUrl })
|
||||
const redisClient = createClient({
|
||||
url: redisUrl,
|
||||
socket: {
|
||||
keepAlive:
|
||||
process.env.REDIS_KEEP_ALIVE && !isNaN(parseInt(process.env.REDIS_KEEP_ALIVE, 10))
|
||||
? parseInt(process.env.REDIS_KEEP_ALIVE, 10)
|
||||
: undefined // milliseconds
|
||||
}
|
||||
})
|
||||
|
||||
const storeConfig: RedisVectorStoreConfig = {
|
||||
redisClient: redisClient,
|
||||
|
||||
Reference in New Issue
Block a user