Skip to content

Commit

Permalink
fix: Add back Pipeline#length
Browse files Browse the repository at this point in the history
Closes #1584
  • Loading branch information
luin committed May 21, 2022
1 parent 91ed2d8 commit b8cee9b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions bin/template.ts
Expand Up @@ -11,8 +11,9 @@ export interface ResultTypes<Result, Context> {
pipeline: ChainableCommander;
}

export interface ChainableCommander
extends RedisCommander<{ type: "pipeline" }> {}
export interface ChainableCommander extends RedisCommander<{ type: "pipeline" }> {
length: number;
}

export type ClientContext = { type: keyof ResultTypes<unknown, unknown> };
export type Result<T, Context extends ClientContext> =
Expand Down
4 changes: 4 additions & 0 deletions lib/Pipeline.ts
Expand Up @@ -392,3 +392,7 @@ Pipeline.prototype.exec = function (callback: Callback): Promise<Array<any>> {
return _this.promise;
}
};

interface Pipeline {
length: number;
}
5 changes: 3 additions & 2 deletions lib/utils/RedisCommander.ts
Expand Up @@ -11,8 +11,9 @@ export interface ResultTypes<Result, Context> {
pipeline: ChainableCommander;
}

export interface ChainableCommander
extends RedisCommander<{ type: "pipeline" }> {}
export interface ChainableCommander extends RedisCommander<{ type: "pipeline" }> {
length: number;
}

export type ClientContext = { type: keyof ResultTypes<unknown, unknown> };
export type Result<T, Context extends ClientContext> =
Expand Down
1 change: 1 addition & 0 deletions test/functional/pipeline.ts
Expand Up @@ -400,6 +400,7 @@ describe("pipeline", () => {

const pipeline1 = redis
.pipeline()
// @ts-expect-error
.multi()
.set("foo", "bar")
.get("foo")
Expand Down
11 changes: 10 additions & 1 deletion test/typing/pipeline.test-d.ts
@@ -1,5 +1,5 @@
import { expectType } from "tsd";
import Redis from "../../built";
import Redis, { Pipeline } from "../../built";

const redis = new Redis();

Expand All @@ -24,3 +24,12 @@ expectType<RETURN_TYPE>(
])
.exec()
);

expectType<number>(
redis.pipeline([
["set", Buffer.from("foo"), "bar"],
["incrby", "foo", 42],
]).length
);

expectType<number>(({} as unknown as Pipeline).length);

0 comments on commit b8cee9b

Please sign in to comment.