Skip to content

Commit c1d69ae

Browse files
committed
addressed all in person review comments
1 parent 21ce0cb commit c1d69ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+922
-2016
lines changed

package-lock.json

+754-1,757
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/client/lib/RESP/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export type CommandArguments = Array<RedisArgument> & { preserve?: unknown };
274274
// };
275275

276276
export type Command = {
277+
CACHEABLE?: boolean;
277278
IS_READ_ONLY?: boolean;
278279
/**
279280
* @internal

packages/client/lib/client/index.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,21 @@ export default class RedisClient<
154154
const transformReply = getTransformReply(command, resp);
155155

156156
return async function (this: ProxyClient, ...args: Array<unknown>) {
157-
const parser = new BasicCommandParser(resp);
157+
const parser = new BasicCommandParser();
158158
command.parseCommand(parser, ...args);
159159

160-
return this._self._executeCommand(parser, this._commandOptions, transformReply);
160+
return this._self._executeCommand(command, parser, this._commandOptions, transformReply);
161161
}
162162
}
163163

164164
static #createModuleCommand(command: Command, resp: RespVersions) {
165165
const transformReply = getTransformReply(command, resp);
166166

167167
return async function (this: NamespaceProxyClient, ...args: Array<unknown>) {
168-
const parser = new BasicCommandParser(resp);
168+
const parser = new BasicCommandParser();
169169
command.parseCommand(parser, ...args);
170170

171-
return this._self._executeCommand(parser, this._self._commandOptions, transformReply);
171+
return this._self._executeCommand(command, parser, this._self._commandOptions, transformReply);
172172
};
173173
}
174174

@@ -177,11 +177,11 @@ export default class RedisClient<
177177
const transformReply = getTransformReply(fn, resp);
178178

179179
return async function (this: NamespaceProxyClient, ...args: Array<unknown>) {
180-
const parser = new BasicCommandParser(resp);
180+
const parser = new BasicCommandParser();
181181
parser.push(...prefix);
182182
fn.parseCommand(parser, ...args);
183183

184-
return this._self._executeCommand(parser, this._self._commandOptions, transformReply);
184+
return this._self._executeCommand(fn, parser, this._self._commandOptions, transformReply);
185185
};
186186
}
187187

@@ -190,7 +190,7 @@ export default class RedisClient<
190190
const transformReply = getTransformReply(script, resp);
191191

192192
return async function (this: ProxyClient, ...args: Array<unknown>) {
193-
const parser = new BasicCommandParser(resp);
193+
const parser = new BasicCommandParser();
194194
parser.push(...prefix);
195195
script.parseCommand(parser, ...args)
196196

@@ -576,6 +576,7 @@ export default class RedisClient<
576576
* @internal
577577
*/
578578
async _executeCommand(
579+
command: Command,
579580
parser: CommandParser,
580581
commandOptions: CommandOptions<TYPE_MAPPING> | undefined,
581582
transformReply: TransformReply | undefined,

packages/client/lib/client/multi-command.ts

+19-26
Original file line numberDiff line numberDiff line change
@@ -91,71 +91,79 @@ export default class RedisClientMultiCommand<REPLIES = []> {
9191
static #createCommand(command: Command, resp: RespVersions) {
9292
const transformReply = getTransformReply(command, resp);
9393

94-
return function (this: RedisClientMultiCommand, ...args: Array<unknown>) {
95-
const parser = new BasicCommandParser(resp);
94+
return function (this: RedisClientMultiCommand, ...args: Array<unknown>): RedisClientMultiCommand {
95+
const parser = new BasicCommandParser();
9696
command.parseCommand(parser, ...args);
9797

9898
const redisArgs: CommandArguments = parser.redisArgs;
9999
redisArgs.preserve = parser.preserve;
100100

101-
return this.addCommand(
101+
this.#multi.addCommand(
102102
redisArgs,
103103
transformReply
104104
);
105+
106+
return this;
105107
};
106108
}
107109

108110
static #createModuleCommand(command: Command, resp: RespVersions) {
109111
const transformReply = getTransformReply(command, resp);
110112

111-
return function (this: { _self: RedisClientMultiCommand }, ...args: Array<unknown>) {
112-
const parser = new BasicCommandParser(resp);
113+
return function (this: { _self: RedisClientMultiCommand }, ...args: Array<unknown>): RedisClientMultiCommand {
114+
const parser = new BasicCommandParser();
113115
command.parseCommand(parser, ...args);
114116

115117
const redisArgs: CommandArguments = parser.redisArgs;
116118
redisArgs.preserve = parser.preserve;
117119

118-
return this._self.addCommand(
120+
this._self.#multi.addCommand(
119121
redisArgs,
120122
transformReply
121123
);
124+
125+
return this._self;
122126
};
123127
}
124128

125129
static #createFunctionCommand(name: string, fn: RedisFunction, resp: RespVersions) {
126130
const prefix = functionArgumentsPrefix(name, fn);
127131
const transformReply = getTransformReply(fn, resp);
128132

129-
return function (this: { _self: RedisClientMultiCommand }, ...args: Array<unknown>) {
130-
const parser = new BasicCommandParser(resp);
133+
return function (this: { _self: RedisClientMultiCommand }, ...args: Array<unknown>): RedisClientMultiCommand {
134+
const parser = new BasicCommandParser();
131135
parser.push(...prefix);
132136
fn.parseCommand(parser, ...args);
133137

134138
const redisArgs: CommandArguments = parser.redisArgs;
135139
redisArgs.preserve = parser.preserve;
136140

137-
return this._self.addCommand(
141+
this._self.#multi.addCommand(
138142
redisArgs,
139143
transformReply
140144
);
145+
146+
return this._self;
141147
};
142148
}
143149

144150
static #createScriptCommand(script: RedisScript, resp: RespVersions) {
145151
const transformReply = getTransformReply(script, resp);
146152

147153
return function (this: RedisClientMultiCommand, ...args: Array<unknown>) {
148-
const parser = new BasicCommandParser(resp);
154+
const parser = new BasicCommandParser();
149155
script.parseCommand(parser, ...args);
150156

151157
const redisArgs: CommandArguments = parser.redisArgs;
152158
redisArgs.preserve = parser.preserve;
153159

154-
return this.addScript(
160+
this.#multi.addScript(
155161
script,
156162
redisArgs,
157163
transformReply
158164
);
165+
166+
return this;
159167
};
160168
}
161169

@@ -196,21 +204,6 @@ export default class RedisClientMultiCommand<REPLIES = []> {
196204

197205
select = this.SELECT;
198206

199-
addCommand(args: CommandArguments, transformReply?: TransformReply) {
200-
this.#multi.addCommand(args, transformReply);
201-
return this;
202-
}
203-
204-
addScript(
205-
script: RedisScript,
206-
args: CommandArguments,
207-
transformReply?: TransformReply
208-
) {
209-
this.#multi.addScript(script, args, transformReply);
210-
211-
return this;
212-
}
213-
214207
async exec<T extends MultiReply = MULTI_REPLY['GENERIC']>(execAsPipeline = false): Promise<MultiReplyType<T, REPLIES>> {
215208
if (execAsPipeline) return this.execAsPipeline<T>();
216209

packages/client/lib/client/parser.ts

+5-35
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { RedisArgument, RespVersions } from "../RESP/types";
2-
import { RedisVariadicArgument } from "../commands/generic-transformers";
1+
import { RedisArgument } from '../RESP/types';
2+
import { RedisVariadicArgument } from '../commands/generic-transformers';
33

44
export interface CommandParser {
55
redisArgs: ReadonlyArray<RedisArgument>;
66
keys: ReadonlyArray<RedisArgument>;
77
firstKey: RedisArgument | undefined;
8-
respVersion: RespVersions;
98
preserve: unknown;
10-
cachable: boolean;
119

1210
push: (...arg: Array<RedisArgument>) => unknown;
1311
pushVariadic: (vals: RedisVariadicArgument) => unknown;
@@ -16,20 +14,12 @@ export interface CommandParser {
1614
pushKey: (key: RedisArgument) => unknown; // normal push of keys
1715
pushKeys: (keys: RedisVariadicArgument) => unknown; // push multiple keys at a time
1816
pushKeysLength: (keys: RedisVariadicArgument) => unknown; // push multiple keys at a time
19-
setCachable: () => unknown;
20-
setPreserve: (val: unknown) => unknown;
2117
}
2218

2319
export class BasicCommandParser implements CommandParser {
2420
#redisArgs: Array<RedisArgument> = [];
2521
#keys: Array<RedisArgument> = [];
26-
#respVersion: RespVersions;
27-
#preserve: unknown;
28-
#cachable: boolean = false;
29-
30-
constructor(respVersion: RespVersions = 2) {
31-
this.#respVersion = respVersion;
32-
}
22+
preserve: unknown;
3323

3424
get redisArgs() {
3525
return this.#redisArgs;
@@ -40,19 +30,7 @@ export class BasicCommandParser implements CommandParser {
4030
}
4131

4232
get firstKey() {
43-
return this.#keys.length != 0 ? this.#keys[0] : undefined;
44-
}
45-
46-
get respVersion() {
47-
return this.#respVersion;
48-
}
49-
50-
get preserve() {
51-
return this.#preserve;
52-
}
53-
54-
get cachable() {
55-
return this.#cachable
33+
return this.#keys[0];
5634
}
5735

5836
push(...arg: Array<RedisArgument>) {
@@ -91,7 +69,7 @@ export class BasicCommandParser implements CommandParser {
9169
pushKey(key: RedisArgument) {
9270
this.#keys.push(key);
9371
this.#redisArgs.push(key);
94-
};
72+
}
9573

9674
pushKeysLength(keys: RedisVariadicArgument) {
9775
if (Array.isArray(keys)) {
@@ -111,12 +89,4 @@ export class BasicCommandParser implements CommandParser {
11189
this.#redisArgs.push(keys);
11290
}
11391
}
114-
115-
setPreserve(val: unknown) {
116-
this.#preserve = val;
117-
}
118-
119-
setCachable() {
120-
this.#cachable = true;
121-
};
12292
}

packages/client/lib/client/pool.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ export class RedisClientPool<
6767
const transformReply = getTransformReply(command, resp);
6868

6969
return async function (this: ProxyPool, ...args: Array<unknown>) {
70-
const parser = new BasicCommandParser(resp);
70+
const parser = new BasicCommandParser();
7171
command.parseCommand(parser, ...args);
7272

73-
return this.execute(client => client._executeCommand(parser, this._commandOptions, transformReply))
73+
return this.execute(client => client._executeCommand(command, parser, this._commandOptions, transformReply))
7474
};
7575
}
7676

7777
static #createModuleCommand(command: Command, resp: RespVersions) {
7878
const transformReply = getTransformReply(command, resp);
7979

8080
return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
81-
const parser = new BasicCommandParser(resp);
81+
const parser = new BasicCommandParser();
8282
command.parseCommand(parser, ...args);
8383

84-
return this._self.execute(client => client._executeCommand(parser, this._self._commandOptions, transformReply))
84+
return this._self.execute(client => client._executeCommand(command, parser, this._self._commandOptions, transformReply))
8585
};
8686
}
8787

@@ -90,19 +90,19 @@ export class RedisClientPool<
9090
const transformReply = getTransformReply(fn, resp);
9191

9292
return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
93-
const parser = new BasicCommandParser(resp);
93+
const parser = new BasicCommandParser();
9494
parser.push(...prefix);
9595
fn.parseCommand(parser, ...args);
9696

97-
return this._self.execute(client => client._executeCommand(parser, this._self._commandOptions, transformReply)) };
97+
return this._self.execute(client => client._executeCommand(fn, parser, this._self._commandOptions, transformReply)) };
9898
}
9999

100100
static #createScriptCommand(script: RedisScript, resp: RespVersions) {
101101
const prefix = scriptArgumentsPrefix(script);
102102
const transformReply = getTransformReply(script, resp);
103103

104104
return async function (this: ProxyPool, ...args: Array<unknown>) {
105-
const parser = new BasicCommandParser(resp);
105+
const parser = new BasicCommandParser();
106106
parser.pushVariadic(prefix);
107107
script.parseCommand(parser, ...args);
108108

packages/client/lib/cluster/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ export default class RedisCluster<
149149
static #createCommand(command: Command, resp: RespVersions) {
150150
const transformReply = getTransformReply(command, resp);
151151
return async function (this: ProxyCluster, ...args: Array<unknown>) {
152-
const parser = new BasicCommandParser(resp);
152+
const parser = new BasicCommandParser();
153153
command.parseCommand(parser, ...args);
154154

155155
return this._self.#execute(
156156
parser.firstKey,
157157
command.IS_READ_ONLY,
158158
this._commandOptions,
159-
(client, opts) => client._executeCommand(parser, opts, transformReply)
159+
(client, opts) => client._executeCommand(command, parser, opts, transformReply)
160160
);
161161
};
162162
}
@@ -165,14 +165,14 @@ export default class RedisCluster<
165165
const transformReply = getTransformReply(command, resp);
166166

167167
return async function (this: NamespaceProxyCluster, ...args: Array<unknown>) {
168-
const parser = new BasicCommandParser(resp);
168+
const parser = new BasicCommandParser();
169169
command.parseCommand(parser, ...args);
170170

171171
return this._self.#execute(
172172
parser.firstKey,
173173
command.IS_READ_ONLY,
174174
this._self._commandOptions,
175-
(client, opts) => client._executeCommand(parser, opts, transformReply)
175+
(client, opts) => client._executeCommand(command, parser, opts, transformReply)
176176
);
177177
};
178178
}
@@ -182,15 +182,15 @@ export default class RedisCluster<
182182
const transformReply = getTransformReply(fn, resp);
183183

184184
return async function (this: NamespaceProxyCluster, ...args: Array<unknown>) {
185-
const parser = new BasicCommandParser(resp);
185+
const parser = new BasicCommandParser();
186186
parser.push(...prefix);
187187
fn.parseCommand(parser, ...args);
188188

189189
return this._self.#execute(
190190
parser.firstKey,
191191
fn.IS_READ_ONLY,
192192
this._self._commandOptions,
193-
(client, opts) => client._executeCommand(parser, opts, transformReply)
193+
(client, opts) => client._executeCommand(fn, parser, opts, transformReply)
194194
);
195195
};
196196
}
@@ -200,7 +200,7 @@ export default class RedisCluster<
200200
const transformReply = getTransformReply(script, resp);
201201

202202
return async function (this: ProxyCluster, ...args: Array<unknown>) {
203-
const parser = new BasicCommandParser(resp);
203+
const parser = new BasicCommandParser();
204204
parser.push(...prefix);
205205
script.parseCommand(parser, ...args);
206206

@@ -419,7 +419,7 @@ export default class RedisCluster<
419419
client = redirectTo;
420420

421421
const chainId = Symbol('Asking Chain');
422-
const myOpts = options ? {...options} : {};
422+
myOpts = options ? {...options} : {};
423423
myOpts.chainId = chainId;
424424

425425
client.sendCommand(parseArgs(ASKING), {chainId: chainId}).catch(err => { console.log(`Asking Failed: ${err}`) } );

0 commit comments

Comments
 (0)