Skip to content

Commit a7caa00

Browse files
committed
BREAKING: rename CommandExecutor to Client
1 parent b2ffaf9 commit a7caa00

File tree

9 files changed

+127
-121
lines changed

9 files changed

+127
-121
lines changed

client.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { Connection, SendCommandOptions } from "./connection.ts";
2+
import type { RedisReply, RedisValue } from "./protocol/shared/types.ts";
3+
4+
export interface Client {
5+
/**
6+
* @deprecated
7+
*/
8+
readonly connection: Connection;
9+
/**
10+
* @deprecated
11+
*/
12+
exec(
13+
command: string,
14+
...args: RedisValue[]
15+
): Promise<RedisReply>;
16+
17+
sendCommand(
18+
command: string,
19+
args?: RedisValue[],
20+
options?: SendCommandOptions,
21+
): Promise<RedisReply>;
22+
23+
/**
24+
* Closes a redis connection.
25+
*/
26+
close(): void;
27+
}
28+
29+
export class DefaultClient implements Client {
30+
constructor(readonly connection: Connection) {}
31+
32+
exec(
33+
command: string,
34+
...args: RedisValue[]
35+
): Promise<RedisReply> {
36+
return this.connection.sendCommand(command, args);
37+
}
38+
39+
sendCommand(
40+
command: string,
41+
args?: RedisValue[],
42+
options?: SendCommandOptions,
43+
) {
44+
return this.connection.sendCommand(command, args, options);
45+
}
46+
47+
close(): void {
48+
this.connection.close();
49+
}
50+
}

executor.ts

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,4 @@
1-
import type { Connection, SendCommandOptions } from "./connection.ts";
2-
import type { RedisReply, RedisValue } from "./protocol/shared/types.ts";
1+
import type { Client } from "./client.ts";
32

4-
export interface CommandExecutor {
5-
/**
6-
* @deprecated
7-
*/
8-
readonly connection: Connection;
9-
/**
10-
* @deprecated
11-
*/
12-
exec(
13-
command: string,
14-
...args: RedisValue[]
15-
): Promise<RedisReply>;
16-
17-
sendCommand(
18-
command: string,
19-
args?: RedisValue[],
20-
options?: SendCommandOptions,
21-
): Promise<RedisReply>;
22-
23-
/**
24-
* Closes a redis connection.
25-
*/
26-
close(): void;
27-
}
28-
29-
export class DefaultExecutor implements CommandExecutor {
30-
constructor(readonly connection: Connection) {}
31-
32-
exec(
33-
command: string,
34-
...args: RedisValue[]
35-
): Promise<RedisReply> {
36-
return this.connection.sendCommand(command, args);
37-
}
38-
39-
sendCommand(
40-
command: string,
41-
args?: RedisValue[],
42-
options?: SendCommandOptions,
43-
) {
44-
return this.connection.sendCommand(command, args, options);
45-
}
46-
47-
close(): void {
48-
this.connection.close();
49-
}
50-
}
3+
/** @deprecated Use {@linkcode Client} instead. */
4+
export type CommandExecutor = Client;

experimental/cluster/mod.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import { connect, create } from "../../redis.ts";
3030
import type { RedisConnectOptions } from "../../redis.ts";
31-
import type { CommandExecutor } from "../../executor.ts";
31+
import type { Client } from "../../client.ts";
3232
import type { Connection, SendCommandOptions } from "../../connection.ts";
3333
import type { Redis } from "../../redis.ts";
3434
import type { RedisReply, RedisValue } from "../../protocol/shared/types.ts";
@@ -74,7 +74,7 @@ const kRedisClusterRequestTTL = 16;
7474

7575
class ClusterError extends Error {}
7676

77-
class ClusterExecutor implements CommandExecutor {
77+
class ClusterClient implements Client {
7878
#nodeBySlot!: SlotMap;
7979
#startupNodes: ClusterNode[];
8080
#refreshTableASAP?: boolean;
@@ -338,9 +338,9 @@ function getKeyFromCommand(command: string, args: RedisValue[]): string | null {
338338
* @see https://redis.io/topics/cluster-spec
339339
*/
340340
async function connectToCluster(opts: ClusterConnectOptions): Promise<Redis> {
341-
const executor = new ClusterExecutor(opts);
342-
await executor.initializeSlotsCache();
343-
return create(executor);
341+
const client = new ClusterClient(opts);
342+
await client.initializeSlotsCache();
343+
return create(client);
344344
}
345345

346346
export { connectToCluster as connect };

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type {
6767
ConnectionEventType,
6868
ConnectionReconnectingEventDetails,
6969
} from "./events.ts";
70+
export type { Client } from "./client.ts";
7071
export type { CommandExecutor } from "./executor.ts";
7172
export type { RedisPipeline } from "./pipeline.ts";
7273
export type {

pipeline.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Connection, SendCommandOptions } from "./connection.ts";
22
import { kEmptyRedisArgs } from "./connection.ts";
3-
import type { CommandExecutor } from "./executor.ts";
3+
import type { Client } from "./client.ts";
44
import type {
55
RawOrError,
66
RedisReply,
@@ -19,15 +19,15 @@ export function createRedisPipeline(
1919
connection: Connection,
2020
tx = false,
2121
): RedisPipeline {
22-
const executor = new PipelineExecutor(connection, tx);
22+
const pipeline = new PipelineClient(connection, tx);
2323
function flush(): Promise<RawOrError[]> {
24-
return executor.flush();
24+
return pipeline.flush();
2525
}
26-
const client = create(executor);
26+
const client = create(pipeline);
2727
return Object.assign(client, { flush });
2828
}
2929

30-
export class PipelineExecutor implements CommandExecutor {
30+
class PipelineClient implements Client {
3131
private commands: {
3232
command: string;
3333
args: RedisValue[];

pool/executor.ts renamed to pool/client.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import type { Connection, SendCommandOptions } from "../connection.ts";
22
import type { Pool } from "./pool.ts";
3-
import type { CommandExecutor } from "../executor.ts";
4-
import { DefaultExecutor } from "../executor.ts";
3+
import type { Client } from "../client.ts";
4+
import { DefaultClient } from "../client.ts";
55
import type { RedisReply, RedisValue } from "../protocol/shared/types.ts";
66

7-
export function createPooledExecutor(pool: Pool<Connection>): CommandExecutor {
8-
return new PooledExecutor(pool);
7+
export function createPoolClient(pool: Pool<Connection>): Client {
8+
return new PoolClient(pool);
99
}
1010

11-
class PooledExecutor implements CommandExecutor {
11+
class PoolClient implements Client {
1212
readonly #pool: Pool<Connection>;
1313
constructor(pool: Pool<Connection>) {
1414
this.#pool = pool;
1515
}
1616

1717
get connection(): Connection {
18-
throw new Error("PooledExecutor.connection is not supported");
18+
throw new Error("PoolClient.connection is not supported");
1919
}
2020

2121
async exec(
@@ -24,8 +24,8 @@ class PooledExecutor implements CommandExecutor {
2424
): Promise<RedisReply> {
2525
const connection = await this.#pool.acquire();
2626
try {
27-
const executor = new DefaultExecutor(connection);
28-
return await executor.exec(command, ...args);
27+
const client = new DefaultClient(connection);
28+
return await client.exec(command, ...args);
2929
} finally {
3030
this.#pool.release(connection);
3131
}
@@ -38,8 +38,8 @@ class PooledExecutor implements CommandExecutor {
3838
): Promise<RedisReply> {
3939
const connection = await this.#pool.acquire();
4040
try {
41-
const executor = new DefaultExecutor(connection);
42-
return await executor.sendCommand(command, args, options);
41+
const client = new DefaultClient(connection);
42+
return await client.sendCommand(command, args, options);
4343
} finally {
4444
this.#pool.release(connection);
4545
}

pool/mod.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { create } from "../redis.ts";
33
import type { Connection } from "../connection.ts";
44
import { createRedisConnection } from "../connection.ts";
55
import { createDefaultPool } from "./default_pool.ts";
6-
import { createPooledExecutor } from "./executor.ts";
6+
import { createPoolClient as baseCreatePoolClient } from "./client.ts";
77

88
export interface CreatePoolClientOptions {
99
connection: RedisConnectOptions;
@@ -17,8 +17,7 @@ export function createPoolClient(
1717
acquire,
1818
maxConnections: options.maxConnections ?? 8,
1919
});
20-
const executor = createPooledExecutor(pool);
21-
const client = create(executor);
20+
const client = create(baseCreatePoolClient(pool));
2221
return Promise.resolve(client);
2322

2423
async function acquire(): Promise<Connection> {

pubsub.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CommandExecutor } from "./executor.ts";
1+
import type { Client } from "./client.ts";
22
import { isRetriableError } from "./errors.ts";
33
import type { Binary } from "./protocol/shared/types.ts";
44
import { decoder } from "./internal/encoding.ts";
@@ -33,17 +33,17 @@ class RedisSubscriptionImpl<
3333
TMessage extends ValidMessageType = DefaultMessageType,
3434
> implements RedisSubscription<TMessage> {
3535
get isConnected(): boolean {
36-
return this.executor.connection.isConnected;
36+
return this.client.connection.isConnected;
3737
}
3838

3939
get isClosed(): boolean {
40-
return this.executor.connection.isClosed;
40+
return this.client.connection.isClosed;
4141
}
4242

4343
private channels = Object.create(null);
4444
private patterns = Object.create(null);
4545

46-
constructor(private executor: CommandExecutor) {}
46+
constructor(private client: Client) {}
4747

4848
async psubscribe(...patterns: string[]) {
4949
await this.#writeCommand("PSUBSCRIBE", patterns);
@@ -89,7 +89,7 @@ class RedisSubscriptionImpl<
8989
RedisPubSubMessage<T>
9090
> {
9191
let forceReconnect = false;
92-
const connection = this.executor.connection;
92+
const connection = this.client.connection;
9393
while (this.isConnected) {
9494
try {
9595
let rep: [string | Binary, string | Binary, T] | [
@@ -156,32 +156,32 @@ class RedisSubscriptionImpl<
156156
}
157157

158158
close() {
159-
this.executor.connection.close();
159+
this.client.connection.close();
160160
}
161161

162162
async #writeCommand(command: string, args: Array<string>): Promise<void> {
163-
await this.executor.connection[kUnstableWriteCommand]({ command, args });
163+
await this.client.connection[kUnstableWriteCommand]({ command, args });
164164
}
165165
}
166166

167167
export async function subscribe<
168168
TMessage extends ValidMessageType = DefaultMessageType,
169169
>(
170-
executor: CommandExecutor,
170+
client: Client,
171171
...channels: string[]
172172
): Promise<RedisSubscription<TMessage>> {
173-
const sub = new RedisSubscriptionImpl<TMessage>(executor);
173+
const sub = new RedisSubscriptionImpl<TMessage>(client);
174174
await sub.subscribe(...channels);
175175
return sub;
176176
}
177177

178178
export async function psubscribe<
179179
TMessage extends ValidMessageType = DefaultMessageType,
180180
>(
181-
executor: CommandExecutor,
181+
client: Client,
182182
...patterns: string[]
183183
): Promise<RedisSubscription<TMessage>> {
184-
const sub = new RedisSubscriptionImpl<TMessage>(executor);
184+
const sub = new RedisSubscriptionImpl<TMessage>(client);
185185
await sub.psubscribe(...patterns);
186186
return sub;
187187
}

0 commit comments

Comments
 (0)