Skip to content

Commit f33a2c8

Browse files
authored
fix: remove unnecessary case-sensitivity when working with commands (#2036)
* fix: remove unnecessary case-sensitivity when working with commands * fix-1913 update commands version
1 parent 105dc72 commit f33a2c8

File tree

7 files changed

+39
-13
lines changed

7 files changed

+39
-13
lines changed

lib/Command.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export default class Command implements Respondable {
119119
flagName: T,
120120
commandName: string
121121
): commandName is CommandNameFlags[T][number] {
122+
commandName = commandName.toLowerCase();
122123
return !!this.getFlagMap()[flagName][commandName];
123124
}
124125

@@ -358,9 +359,11 @@ export default class Command implements Respondable {
358359
): (string | Buffer)[] {
359360
if (typeof this.keys === "undefined") {
360361
this.keys = [];
361-
if (exists(this.name)) {
362+
if (exists(this.name, { caseInsensitive: true })) {
362363
// @ts-expect-error
363-
const keyIndexes = getKeyIndexes(this.name, this.args);
364+
const keyIndexes = getKeyIndexes(this.name, this.args, {
365+
nameCaseInsensitive: true,
366+
});
364367
for (const index of keyIndexes) {
365368
this.args[index] = transform(this.args[index]);
366369
this.keys.push(this.args[index] as string | Buffer);

lib/Pipeline.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class Pipeline extends Commander<{ type: "pipeline" }> {
123123
}
124124
} else if (!command.inTransaction) {
125125
const isReadOnly =
126-
exists(command.name) && hasFlag(command.name, "readonly");
126+
exists(command.name, { caseInsensitive: true }) &&
127+
hasFlag(command.name, "readonly", { nameCaseInsensitive: true });
127128
if (!isReadOnly) {
128129
retriable = false;
129130
break;

lib/Redis.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ class Redis extends Commander implements DataHandledable {
449449
this.status === "ready" ||
450450
(!stream &&
451451
this.status === "connect" &&
452-
exists(command.name) &&
453-
(hasFlag(command.name, "loading") ||
452+
exists(command.name, { caseInsensitive: true }) &&
453+
(hasFlag(command.name, "loading", { nameCaseInsensitive: true }) ||
454454
Command.checkFlag("HANDSHAKE_COMMANDS", command.name)));
455455
if (!this.stream) {
456456
writable = false;

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"url": "https://opencollective.com/ioredis"
4444
},
4545
"dependencies": {
46-
"@ioredis/commands": "1.4.0",
46+
"@ioredis/commands": "1.5.0",
4747
"cluster-key-slot": "^1.1.0",
4848
"debug": "^4.3.4",
4949
"denque": "^2.1.0",

test/functional/transformer.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,17 @@ describe("transformer", () => {
183183
});
184184
});
185185
});
186+
187+
describe("call", () => {
188+
it("keyPrefix should be case insensitive for command name", async () => {
189+
const redis = new Redis({ keyPrefix: "foo:" });
190+
191+
const value = "value1";
192+
expect(await redis.call("SeT", "mykey", value)).to.eql("OK");
193+
194+
const otherRedis = new Redis();
195+
expect(await otherRedis.call("get", "foo:mykey")).to.eql(value);
196+
});
197+
});
186198
});
187199
});

test/unit/command.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,15 @@ describe("Command", () => {
165165
);
166166
expect(Command.checkFlag("WILL_DISCONNECT", "quit")).to.eql(true);
167167
});
168+
169+
it('should be case insensitive for command name', () => {
170+
expect(Command.checkFlag("VALID_IN_SUBSCRIBER_MODE", "PING")).to.eql(
171+
true
172+
);
173+
expect(Command.checkFlag("VALID_IN_SUBSCRIBER_MODE", "Get")).to.eql(
174+
false
175+
);
176+
expect(Command.checkFlag("WILL_DISCONNECT", "QuIt")).to.eql(true);
177+
});
168178
});
169179
});

0 commit comments

Comments
 (0)