Skip to content
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

fix: send correct command during auto-pipelining of .call() operations #1841

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/autoPipelining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,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", function () {
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", function () {
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", function () {
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", function () {

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