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 #1579

Merged
merged 2 commits into from May 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/autoPipelining.ts
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
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