Skip to content

Commit

Permalink
Fix legacyMode/pingInterval issue (#2386)
Browse files Browse the repository at this point in the history
* 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 <me@leibale.com>
  • Loading branch information
benjie and leibale committed Jan 25, 2023
1 parent 85bf97b commit 2287efd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/client/lib/client/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ describe('Client', () => {
legacyMode: true
}
});

testUtils.testWithClient('pingInterval', async client => {
assert.deepEqual(
await once(client, 'ping-interval'),
['PONG']
);
}, {
...GLOBAL.SERVERS.OPEN,
clientOptions: {
legacyMode: true,
pingInterval: 1
}
});
});

describe('events', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ export default class RedisClient<
this.#pingTimer = setTimeout(() => {
if (!this.#socket.isReady) return;

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

0 comments on commit 2287efd

Please sign in to comment.