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: Add back Pipeline#length #1585

Merged
merged 1 commit into from May 31, 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
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
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);