Skip to content

Commit e41c3dc

Browse files
Fuslluin
andauthored
fix: send correct command during auto-pipelining of .call() operations (#1579)
Co-authored-by: Zihua Li <[email protected]>
1 parent f9f875b commit e41c3dc

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Diff for: lib/autoPipelining.ts

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ export function executeWithAutoPipelining(
185185
resolve(value);
186186
});
187187

188+
if (functionName === "call") {
189+
args.unshift(commandName);
190+
}
191+
188192
pipeline[functionName](...args);
189193
});
190194

Diff for: test/functional/autopipelining.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("autoPipelining for single node", () => {
4747
it("should support buffer commands", async () => {
4848
const redis = new Redis({ enableAutoPipelining: true });
4949
const buffer = Buffer.from("bar");
50-
await redis.setBuffer("foo", buffer);
50+
await redis.set("foo", buffer);
5151
const promise = redis.getBuffer("foo");
5252
expect(redis.autoPipelineQueueSize).to.eql(1);
5353
expect(await promise).to.eql(buffer);
@@ -56,16 +56,33 @@ describe("autoPipelining for single node", () => {
5656
it("should support custom commands", async () => {
5757
const redis = new Redis({ enableAutoPipelining: true });
5858

59-
redis.defineCommand("echo", {
59+
redis.defineCommand("myecho", {
6060
numberOfKeys: 2,
6161
lua: "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
6262
});
6363

64-
const promise = redis.echo("foo1", "foo2", "bar1", "bar2");
64+
// @ts-expect-error
65+
const promise = redis.myecho("foo1", "foo2", "bar1", "bar2");
6566
expect(redis.autoPipelineQueueSize).to.eql(1);
6667
expect(await promise).to.eql(["foo1", "foo2", "bar1", "bar2"]);
6768

68-
await redis.echo("foo1", "foo2", "bar1", "bar2");
69+
// @ts-expect-error
70+
await redis.myecho("foo1", "foo2", "bar1", "bar2");
71+
});
72+
73+
it("should support call()", async () => {
74+
const redis = new Redis({ enableAutoPipelining: true });
75+
await redis.call("set", "foo", "call()");
76+
77+
expect(
78+
await Promise.all([
79+
redis.get("foo"),
80+
redis.get("foo"),
81+
redis.get("foo"),
82+
redis.get("foo"),
83+
redis.get("foo"),
84+
])
85+
).to.eql(["call()", "call()", "call()", "call()", "call()"]);
6986
});
7087

7188
it("should support multiple commands", async () => {
@@ -133,6 +150,7 @@ describe("autoPipelining for single node", () => {
133150
it("should handle rejections", async () => {
134151
const redis = new Redis({ enableAutoPipelining: true });
135152
await redis.set("foo", "bar");
153+
// @ts-expect-error
136154
await expect(redis.set("foo")).to.eventually.be.rejectedWith(
137155
"ERR wrong number of arguments for 'set' command"
138156
);
@@ -180,6 +198,7 @@ describe("autoPipelining for single node", () => {
180198

181199
expect(redis.autoPipelineQueueSize).to.eql(1);
182200

201+
// @ts-expect-error
183202
redis.set("foo2", (err) => {
184203
expect(err.message).to.include(
185204
"ERR wrong number of arguments for 'set' command"

0 commit comments

Comments
 (0)