Skip to content

Commit

Permalink
fix: send correct command during auto-pipelining of .call() operations (
Browse files Browse the repository at this point in the history
#1579)

Co-authored-by: Zihua Li <i@zihua.li>
  • Loading branch information
Fusl and luin authored May 17, 2022
1 parent f9f875b commit e41c3dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/autoPipelining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export function executeWithAutoPipelining(
resolve(value);
});

if (functionName === "call") {
args.unshift(commandName);
}

pipeline[functionName](...args);
});

Expand Down
27 changes: 23 additions & 4 deletions test/functional/autopipelining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("autoPipelining for single node", () => {
it("should support buffer commands", async () => {
const redis = new Redis({ enableAutoPipelining: true });
const buffer = Buffer.from("bar");
await redis.setBuffer("foo", buffer);
await redis.set("foo", buffer);
const promise = redis.getBuffer("foo");
expect(redis.autoPipelineQueueSize).to.eql(1);
expect(await promise).to.eql(buffer);
Expand All @@ -56,16 +56,33 @@ describe("autoPipelining for single node", () => {
it("should support custom commands", async () => {
const redis = new Redis({ enableAutoPipelining: true });

redis.defineCommand("echo", {
redis.defineCommand("myecho", {
numberOfKeys: 2,
lua: "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}",
});

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

await redis.echo("foo1", "foo2", "bar1", "bar2");
// @ts-expect-error
await redis.myecho("foo1", "foo2", "bar1", "bar2");
});

it("should support call()", async () => {
const redis = new Redis({ enableAutoPipelining: true });
await redis.call("set", "foo", "call()");

expect(
await Promise.all([
redis.get("foo"),
redis.get("foo"),
redis.get("foo"),
redis.get("foo"),
redis.get("foo"),
])
).to.eql(["call()", "call()", "call()", "call()", "call()"]);
});

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

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

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

0 comments on commit e41c3dc

Please sign in to comment.