Skip to content

fix #2398 - fix v4 interface in legacyMode #2402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/client/lib/client/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils';
import RedisClient, { RedisClientType } from '.';
import { RedisClientMultiCommandType } from './multi-command';
import { RedisCommandArguments, RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands';
import { RedisCommandRawReply, RedisModules, RedisFunctions, RedisScripts } from '../commands';
import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, SocketClosedUnexpectedlyError, WatchError } from '../errors';
import { defineScript } from '../lua-script';
import { spy } from 'sinon';
Expand Down Expand Up @@ -199,6 +199,18 @@ describe('Client', () => {
}
});

testUtils.testWithClient('client.v4.{command} should return a promise', async client => {
assert.equal(
await client.v4.ping(),
'PONG'
);
}, {
...GLOBAL.SERVERS.OPEN,
clientOptions: {
legacyMode: true
}
});

testUtils.testWithClient('client.{command} should accept vardict arguments', async client => {
assert.equal(
await promisify(client.set).call(client, 'a', 'b'),
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export default class RedisClient<

for (const [ name, command ] of Object.entries(COMMANDS as RedisCommands)) {
this.#defineLegacyCommand(name, command);
(this as any)[name.toLowerCase()] = (this as any)[name];
(this as any)[name.toLowerCase()] ??= (this as any)[name];
}

// hard coded commands
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/client/multi-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class RedisClientMultiCommand {

for (const [ name, command ] of Object.entries(COMMANDS as RedisCommands)) {
this.#defineLegacyCommand(name, command);
(this as any)[name.toLowerCase()] = (this as any)[name];
(this as any)[name.toLowerCase()] ??= (this as any)[name];
}
}

Expand Down