diff --git a/lib/Redis.ts b/lib/Redis.ts index 1df870ff5..edb210067 100644 --- a/lib/Redis.ts +++ b/lib/Redis.ts @@ -213,10 +213,6 @@ class Redis extends Commander { } _this.stream = stream; - if (typeof options.keepAlive === "number") { - stream.setKeepAlive(true, options.keepAlive); - } - if (stream.connecting) { stream.once(CONNECT_EVENT, eventHandler.connectHandler(_this)); diff --git a/lib/redis/event_handler.ts b/lib/redis/event_handler.ts index 8b3b57d03..6121e4918 100644 --- a/lib/redis/event_handler.ts +++ b/lib/redis/event_handler.ts @@ -16,6 +16,10 @@ export function connectHandler(self) { self.resetCommandQueue(); + if (typeof self.options.keepAlive === "number") { + self.stream.setKeepAlive(true, self.options.keepAlive); + } + // AUTH command should be processed before any other commands let flushed = false; const { connectionEpoch } = self;