Skip to content

Commit 7af0cfc

Browse files
committed
Achieved pipeline client.
1 parent 51585bb commit 7af0cfc

File tree

9 files changed

+1200
-96
lines changed

9 files changed

+1200
-96
lines changed

src/lib/BaseClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ProtocolClient } from "./ProtocolClient";
44
export abstract class BaseClient
55
extends ProtocolClient {
66

7-
private _password!: string;
7+
protected _password!: string;
88

99
public constructor(
1010
host: string,

src/lib/RedisClient.ts renamed to src/lib/CommandClient.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import * as C from "./Common";
33
import * as U from "./Utils";
44
import { BaseClient } from "./BaseClient";
5+
import { PipelineClient } from "./PipelineClient";
56

6-
export class RedisCommandClient
7+
export class CommandClient
78
extends BaseClient
89
implements C.ICommandClient {
910

@@ -818,4 +819,16 @@ implements C.ICommandClient {
818819

819820
return this.command("PUBSUB", ["NUMPAT"]);
820821
}
822+
823+
public async pipeline(): Promise<C.IPipelineClient> {
824+
825+
const cli = new PipelineClient(this.host, this.port, this._decoder, this._encoder);
826+
827+
if (this._password) {
828+
829+
await cli.auth(this._password);
830+
}
831+
832+
return cli;
833+
}
821834
}

src/lib/Commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type TProcessor = null | ((data: any, args: any[]) => any);
1313

1414
export interface ICommand {
1515

16-
prepare?(...args: any[]): IPrepareResult;
16+
prepare(...args: any[]): IPrepareResult;
1717

1818
process?: TProcessor;
1919
}

src/lib/Common.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,13 @@ export interface ICommandAPIs {
900900
pubSubNumPat(): Promise<number>;
901901
}
902902

903-
export interface ICommandClient extends IProtocolClient, ICommandAPIs {}
903+
export interface ICommandClient extends IProtocolClient, ICommandAPIs {
904+
905+
/**
906+
* Create a client for multi-exec transaction.
907+
*/
908+
pipeline(): Promise<IPipelineClient>;
909+
}
904910

905911
export type IPipelineCommandAPIs = {
906912

src/lib/ModuleAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Decoder } from "./Decoder";
22
import { Encoder } from "./Encoder";
33
import { ProtocolClient } from "./ProtocolClient";
4-
import { RedisCommandClient } from "./RedisClient";
4+
import { CommandClient } from "./CommandClient";
55
import { SubscriberClient } from "./Subscriber";
66
import * as C from "./Common";
77
import { DEFUALT_PORT } from "./Constants";
@@ -23,7 +23,7 @@ export function createCommandClient(
2323
encoder: C.IEncoder = createEncoder()
2424
): C.ICommandClient {
2525

26-
return new RedisCommandClient(
26+
return new CommandClient(
2727
host,
2828
port,
2929
decoder,

0 commit comments

Comments
 (0)