Skip to content

Commit 2287efd

Browse files
benjieleibale
andauthored
Fix legacyMode/pingInterval issue (#2386)
* Add a test for legacyMode pingInterval * Apply patch to fix legacy mode ping interval * use this.#sendCommand instead of this.#v4 Co-authored-by: Leibale <[email protected]>
1 parent 85bf97b commit 2287efd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/client/lib/client/index.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ describe('Client', () => {
341341
legacyMode: true
342342
}
343343
});
344+
345+
testUtils.testWithClient('pingInterval', async client => {
346+
assert.deepEqual(
347+
await once(client, 'ping-interval'),
348+
['PONG']
349+
);
350+
}, {
351+
...GLOBAL.SERVERS.OPEN,
352+
clientOptions: {
353+
legacyMode: true,
354+
pingInterval: 1
355+
}
356+
});
344357
});
345358

346359
describe('events', () => {

packages/client/lib/client/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ export default class RedisClient<
362362
this.#pingTimer = setTimeout(() => {
363363
if (!this.#socket.isReady) return;
364364

365-
(this as unknown as RedisClientType<M, F, S>).ping()
365+
// using #sendCommand to support legacy mode
366+
this.#sendCommand(['PING'])
366367
.then(reply => this.emit('ping-interval', reply))
367368
.catch(err => this.emit('error', err))
368369
.finally(() => this.#setPingTimer());

0 commit comments

Comments
 (0)