diff --git a/lib/Redis.ts b/lib/Redis.ts index 18121574..fae852e8 100644 --- a/lib/Redis.ts +++ b/lib/Redis.ts @@ -227,12 +227,16 @@ class Redis extends Commander implements DataHandledable { // Node ignores setKeepAlive before connect, therefore we wait for the event: // https://github.com/nodejs/node/issues/31663 if (typeof options.keepAlive === "number") { + + // prevents TypeScript error when used inside arrow function + const { keepAlive } = options; + if (stream.connecting) { stream.once(CONNECT_EVENT, () => { - stream.setKeepAlive(true, options.keepAlive); + stream.setKeepAlive(true, keepAlive); }); } else { - stream.setKeepAlive(true, options.keepAlive); + stream.setKeepAlive(true, keepAlive); } } diff --git a/lib/redis/RedisOptions.ts b/lib/redis/RedisOptions.ts index 26cc90aa..fc48a429 100644 --- a/lib/redis/RedisOptions.ts +++ b/lib/redis/RedisOptions.ts @@ -28,7 +28,7 @@ export interface CommonRedisOptions extends CommanderOptions { * @link https://nodejs.org/api/net.html#socketsetkeepaliveenable-initialdelay * @default 0 */ - keepAlive?: number; + keepAlive?: number | null; /** * Enable/disable the use of Nagle's algorithm. diff --git a/test/unit/redis.ts b/test/unit/redis.ts index 5ede16bd..3158ecbd 100644 --- a/test/unit/redis.ts +++ b/test/unit/redis.ts @@ -99,6 +99,9 @@ describe("Redis", () => { option = getOption("redis://localhost?family=6"); expect(option).to.have.property("family", 6); + + option = getOption(1234, { keepAlive: null }); + expect(option).to.have.property('keepAlive', null); } catch (err) { stub.restore(); throw err;