Skip to content

Commit 7cb467a

Browse files
authored
fix #2398 - fix v4 interface in legacyMode (#2402)
1 parent b3c260a commit 7cb467a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
22
import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils';
33
import RedisClient, { RedisClientType } from '.';
44
import { RedisClientMultiCommandType } from './multi-command';
5-
import { RedisCommandArguments, RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands';
5+
import { RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands';
66
import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, SocketClosedUnexpectedlyError, WatchError } from '../errors';
77
import { defineScript } from '../lua-script';
88
import { spy } from 'sinon';
@@ -199,6 +199,18 @@ describe('Client', () => {
199199
}
200200
});
201201

202+
testUtils.testWithClient('client.v4.{command} should return a promise', async client => {
203+
assert.equal(
204+
await client.v4.ping(),
205+
'PONG'
206+
);
207+
}, {
208+
...GLOBAL.SERVERS.OPEN,
209+
clientOptions: {
210+
legacyMode: true
211+
}
212+
});
213+
202214
testUtils.testWithClient('client.{command} should accept vardict arguments', async client => {
203215
assert.equal(
204216
await promisify(client.set).call(client, 'a', 'b'),

packages/client/lib/client/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export default class RedisClient<
352352

353353
for (const [ name, command ] of Object.entries(COMMANDS as RedisCommands)) {
354354
this.#defineLegacyCommand(name, command);
355-
(this as any)[name.toLowerCase()] = (this as any)[name];
355+
(this as any)[name.toLowerCase()] ??= (this as any)[name];
356356
}
357357

358358
// hard coded commands

packages/client/lib/client/multi-command.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default class RedisClientMultiCommand {
119119

120120
for (const [ name, command ] of Object.entries(COMMANDS as RedisCommands)) {
121121
this.#defineLegacyCommand(name, command);
122-
(this as any)[name.toLowerCase()] = (this as any)[name];
122+
(this as any)[name.toLowerCase()] ??= (this as any)[name];
123123
}
124124
}
125125

0 commit comments

Comments
 (0)