Skip to content

Commit c4328b4

Browse files
committed
change how prefix is handled for script/functions
1 parent 761542b commit c4328b4

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

packages/client/lib/client/index.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default class RedisClient<
158158
const parser = this._self.#newCommandParser(resp);
159159
command.parseCommand(parser, ...args);
160160

161-
return this.executeCommand(undefined, parser, this._commandOptions, transformReply);
161+
return this.executeCommand(parser, this._commandOptions, transformReply);
162162
} else {
163163
const redisArgs = command.transformArguments(...args),
164164
reply = await this.sendCommand(redisArgs, this._commandOptions);
@@ -177,7 +177,7 @@ export default class RedisClient<
177177
const parser = this._self._self.#newCommandParser(resp);
178178
command.parseCommand(parser, ...args);
179179

180-
return this._self.executeCommand(undefined, parser, this._self._commandOptions, transformReply);
180+
return this._self.executeCommand(parser, this._self._commandOptions, transformReply);
181181
} else {
182182
const redisArgs = command.transformArguments(...args),
183183
reply = await this._self.sendCommand(redisArgs, this._self._commandOptions);
@@ -195,9 +195,10 @@ export default class RedisClient<
195195
return async function (this: NamespaceProxyClient, ...args: Array<unknown>) {
196196
if (fn.parseCommand) {
197197
const parser = this._self._self.#newCommandParser(resp);
198+
parser.pushVariadic(prefix);
198199
fn.parseCommand(parser, ...args);
199200

200-
return this._self.executeCommand(prefix, parser, this._self._commandOptions, transformReply);
201+
return this._self.executeCommand(parser, this._self._commandOptions, transformReply);
201202
} else {
202203
const fnArgs = fn.transformArguments(...args),
203204
reply = await this._self.sendCommand(
@@ -218,9 +219,10 @@ export default class RedisClient<
218219
return async function (this: ProxyClient, ...args: Array<unknown>) {
219220
if (script.parseCommand) {
220221
const parser = this._self.#newCommandParser(resp);
222+
parser.pushVariadic(prefix);
221223
script.parseCommand(parser, ...args);
222224

223-
return this.executeCommand(prefix, parser, this._commandOptions, transformReply);
225+
return this.executeCommand(parser, this._commandOptions, transformReply);
224226
} else {
225227
const scriptArgs = script.transformArguments(...args),
226228
redisArgs = prefix.concat(scriptArgs),
@@ -611,15 +613,11 @@ export default class RedisClient<
611613
}
612614

613615
async executeCommand<T = ReplyUnion>(
614-
prefix: Array<string | Buffer> | undefined,
615616
parser: CommandParser,
616617
commandOptions: CommandOptions<TYPE_MAPPING> | undefined,
617618
transformReply: TransformReply | undefined
618619
) {
619-
const redisArgs = prefix ? prefix.concat(parser.redisArgs) : parser.redisArgs;
620-
const fn = () => { return this.sendCommand(redisArgs, commandOptions) };
621-
622-
const reply = await fn();
620+
const reply = await this.sendCommand(parser.redisArgs, commandOptions);
623621

624622
if (transformReply) {
625623
return transformReply(reply, parser.preserve);

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import COMMANDS from '../commands';
22
import RedisMultiCommand, { MULTI_REPLY, MultiReply, MultiReplyType, RedisMultiQueuedCommand } from '../multi-command';
33
import { ReplyWithTypeMapping, CommandReply, Command, CommandArguments, CommanderConfig, RedisFunctions, RedisModules, RedisScripts, RespVersions, TransformReply, RedisScript, RedisFunction, TypeMapping } from '../RESP/types';
4-
import { attachConfig, functionArgumentsPrefix, getTransformReply } from '../commander';
4+
import { attachConfig, functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander';
55
import { BasicCommandParser } from './parser';
66

77
type CommandSignature<
@@ -96,6 +96,7 @@ export default class RedisClientMultiCommand<REPLIES = []> {
9696
if (command.parseCommand) {
9797
const parser = new BasicCommandParser(resp);
9898
command.parseCommand(parser, ...args);
99+
99100
redisArgs = parser.redisArgs;
100101
redisArgs.preserve = parser.preserve;
101102
} else {
@@ -118,6 +119,7 @@ export default class RedisClientMultiCommand<REPLIES = []> {
118119
if (command.parseCommand) {
119120
const parser = new BasicCommandParser(resp);
120121
command.parseCommand(parser, ...args);
122+
121123
redisArgs = parser.redisArgs;
122124
redisArgs.preserve = parser.preserve;
123125
} else {
@@ -140,7 +142,9 @@ export default class RedisClientMultiCommand<REPLIES = []> {
140142

141143
if (fn.parseCommand) {
142144
const parser = new BasicCommandParser(resp);
145+
parser.pushVariadic(prefix);
143146
fn.parseCommand(parser, ...args);
147+
144148
fnArgs = parser.redisArgs;
145149
fnArgs.preserve = parser.preserve;
146150
} else {
@@ -158,27 +162,27 @@ export default class RedisClientMultiCommand<REPLIES = []> {
158162
}
159163

160164
static #createScriptCommand(script: RedisScript, resp: RespVersions) {
165+
const prefix = scriptArgumentsPrefix(script);
161166
const transformReply = getTransformReply(script, resp);
162167

163168
return function (this: RedisClientMultiCommand, ...args: Array<unknown>) {
164169
let redisArgs: CommandArguments;
165170

166171
if (script.parseCommand) {
167172
const parser = new BasicCommandParser(resp);
173+
parser.pushVariadic(prefix);
168174
script.parseCommand(parser, ...args);
175+
169176
redisArgs = parser.redisArgs;
170177
redisArgs.preserve = parser.preserve;
171178
} else {
172179
redisArgs = script.transformArguments(...args);
173180
}
174181

175-
this.#multi.addScript(
176-
script,
182+
return this.addCommand(
177183
redisArgs,
178184
transformReply
179185
);
180-
181-
return this;
182186
};
183187
}
184188

packages/client/lib/client/pool.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class RedisClientPool<
6767
const parser = this._self.#newCommandParser(resp);
6868
command.parseCommand(parser, ...args);
6969

70-
return this.execute(client => client.executeCommand(undefined, parser, this._commandOptions, transformReply))
70+
return this.execute(client => client.executeCommand(parser, this._commandOptions, transformReply))
7171
} else {
7272
const redisArgs = command.transformArguments(...args),
7373
reply = await this.sendCommand(redisArgs, this._commandOptions);
@@ -86,7 +86,7 @@ export class RedisClientPool<
8686
const parser = this._self._self.#newCommandParser(resp);
8787
command.parseCommand(parser, ...args);
8888

89-
return this._self.execute(client => client.executeCommand(undefined, parser, this._self._commandOptions, transformReply))
89+
return this._self.execute(client => client.executeCommand(parser, this._self._commandOptions, transformReply))
9090
} else {
9191
const redisArgs = command.transformArguments(...args),
9292
reply = await this._self.sendCommand(redisArgs, this._self._commandOptions);
@@ -104,9 +104,10 @@ export class RedisClientPool<
104104
return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
105105
if (fn.parseCommand) {
106106
const parser = this._self.#newCommandParser(resp);
107+
parser.pushVariadic(prefix);
107108
fn.parseCommand(parser, ...args);
108109

109-
return this._self.execute(client => client.executeCommand(prefix, parser, this._self._commandOptions, transformReply))
110+
return this._self.execute(client => client.executeCommand(parser, this._self._commandOptions, transformReply))
110111
} else {
111112
const fnArgs = fn.transformArguments(...args),
112113
reply = await this._self.sendCommand(
@@ -127,9 +128,10 @@ export class RedisClientPool<
127128
return async function (this: ProxyPool, ...args: Array<unknown>) {
128129
if (script.parseCommand) {
129130
const parser = this._self.#newCommandParser(resp);
131+
parser.pushVariadic(prefix);
130132
script.parseCommand(parser, ...args);
131133

132-
return this.execute(client => client.executeCommand(prefix, parser, this._commandOptions, transformReply))
134+
return this.execute(client => client.executeCommand(parser, this._commandOptions, transformReply))
133135
} else {
134136
const scriptArgs = script.transformArguments(...args),
135137
redisArgs = prefix.concat(scriptArgs),

packages/client/lib/cluster/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default class RedisCluster<
181181
parser.firstKey,
182182
command.IS_READ_ONLY,
183183
this._commandOptions,
184-
(client, opts) => client.executeCommand(undefined, parser, opts, transformReply)
184+
(client, opts) => client.executeCommand(parser, opts, transformReply)
185185
);
186186
} else {
187187
const redisArgs = command.transformArguments(...args);
@@ -218,7 +218,7 @@ export default class RedisCluster<
218218
parser.firstKey,
219219
command.IS_READ_ONLY,
220220
this._self._commandOptions,
221-
(client, opts) => client.executeCommand(undefined, parser, opts, transformReply)
221+
(client, opts) => client.executeCommand(parser, opts, transformReply)
222222
);
223223
} else {
224224
const redisArgs = command.transformArguments(...args);
@@ -249,13 +249,14 @@ export default class RedisCluster<
249249
return async function (this: NamespaceProxyCluster, ...args: Array<unknown>) {
250250
if (fn.parseCommand) {
251251
const parser = this._self._self.#newCommandParser(resp);
252+
parser.pushVariadic(prefix);
252253
fn.parseCommand(parser, ...args);
253254

254255
return this._self.#execute(
255256
parser.firstKey,
256257
fn.IS_READ_ONLY,
257258
this._self._commandOptions,
258-
(client, opts) => client.executeCommand(prefix, parser, opts, transformReply)
259+
(client, opts) => client.executeCommand(parser, opts, transformReply)
259260
);
260261
} else {
261262
const fnArgs = fn.transformArguments(...args);
@@ -287,13 +288,14 @@ export default class RedisCluster<
287288
return async function (this: ProxyCluster, ...args: Array<unknown>) {
288289
if (script.parseCommand) {
289290
const parser = this._self.#newCommandParser(resp);
291+
parser.pushVariadic(prefix);
290292
script.parseCommand(parser, ...args);
291293

292294
return this._self.#execute(
293295
parser.firstKey,
294296
script.IS_READ_ONLY,
295297
this._commandOptions,
296-
(client, opts) => client.executeCommand(prefix, parser, opts, transformReply)
298+
(client, opts) => client.executeCommand(parser, opts, transformReply)
297299
);
298300
} else {
299301
const scriptArgs = script.transformArguments(...args),

packages/client/lib/sentinel/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function createCommand<T extends ProxySentinel | ProxySentinelClient>(com
4545

4646
return this._self._execute(
4747
command.IS_READ_ONLY,
48-
client => client.executeCommand(undefined, parser, this.commandOptions, transformReply)
48+
client => client.executeCommand(parser, this.commandOptions, transformReply)
4949
);
5050
} else {
5151
const redisArgs = command.transformArguments(...args);
@@ -69,11 +69,12 @@ export function createFunctionCommand<T extends NamespaceProxySentinel | Namespa
6969
return async function (this: T, ...args: Array<unknown>) {
7070
if (fn.parseCommand) {
7171
const parser = this._self._self.newCommandParser(resp);
72+
parser.pushVariadic(prefix);
7273
fn.parseCommand(parser, ...args);
7374

7475
return this._self._execute(
7576
fn.IS_READ_ONLY,
76-
client => client.executeCommand(prefix, parser, this._self.commandOptions, transformReply)
77+
client => client.executeCommand(parser, this._self.commandOptions, transformReply)
7778
);
7879
} else {
7980
const fnArgs = fn.transformArguments(...args),
@@ -101,7 +102,7 @@ export function createModuleCommand<T extends NamespaceProxySentinel | Namespace
101102

102103
return this._self._execute(
103104
command.IS_READ_ONLY,
104-
client => client.executeCommand(undefined, parser, this._self.commandOptions, transformReply)
105+
client => client.executeCommand(parser, this._self.commandOptions, transformReply)
105106
);
106107
} else {
107108
const redisArgs = command.transformArguments(...args),
@@ -125,11 +126,12 @@ export function createScriptCommand<T extends ProxySentinel | ProxySentinelClien
125126
return async function (this: T, ...args: Array<unknown>) {
126127
if (script.parseCommand) {
127128
const parser = this._self.newCommandParser(resp);
129+
parser.pushVariadic(prefix);
128130
script.parseCommand(parser, ...args);
129131

130132
return this._self._execute(
131133
script.IS_READ_ONLY,
132-
client => client.executeCommand(prefix, parser, this.commandOptions, transformReply)
134+
client => client.executeCommand(parser, this.commandOptions, transformReply)
133135
);
134136
} else {
135137
const scriptArgs = script.transformArguments(...args),

0 commit comments

Comments
 (0)