@@ -3,6 +3,7 @@ import RedisMultiCommand, { MULTI_REPLY, MultiReply, MultiReplyType, RedisMultiQ
3
3
import { ReplyWithTypeMapping , CommandReply , Command , CommandArguments , CommanderConfig , RedisFunctions , RedisModules , RedisScripts , RespVersions , TransformReply , RedisScript , RedisFunction , TypeMapping , RedisArgument } from '../RESP/types' ;
4
4
import { attachConfig , functionArgumentsPrefix , getTransformReply } from '../commander' ;
5
5
import RedisCluster from '.' ;
6
+ import { BasicClusterCommandParser } from '../client/parser' ;
6
7
7
8
type CommandSignature <
8
9
REPLIES extends Array < unknown > ,
@@ -93,13 +94,24 @@ export type ClusterMultiExecute = (
93
94
export default class RedisClusterMultiCommand < REPLIES = [ ] > {
94
95
static #createCommand( command : Command , resp : RespVersions ) {
95
96
const transformReply = getTransformReply ( command , resp ) ;
97
+
96
98
return function ( this : RedisClusterMultiCommand , ...args : Array < unknown > ) {
97
- const redisArgs = command . transformArguments ( ...args ) ,
99
+ let redisArgs : CommandArguments = [ ] ;
100
+ let firstKey : RedisArgument | undefined ;
101
+
102
+ if ( command . parseCommand ) {
103
+ const parser = new BasicClusterCommandParser ( resp ) ;
104
+ command . parseCommand ( parser , ...args ) ;
105
+ firstKey = parser . firstKey ;
106
+ } else {
107
+ redisArgs = command . transformArguments ( ...args ) ;
98
108
firstKey = RedisCluster . extractFirstKey (
99
109
command ,
100
110
args ,
101
111
redisArgs
102
112
) ;
113
+ }
114
+
103
115
return this . addCommand (
104
116
firstKey ,
105
117
command . IS_READ_ONLY ,
@@ -111,13 +123,23 @@ export default class RedisClusterMultiCommand<REPLIES = []> {
111
123
112
124
static #createModuleCommand( command : Command , resp : RespVersions ) {
113
125
const transformReply = getTransformReply ( command , resp ) ;
126
+
114
127
return function ( this : { _self : RedisClusterMultiCommand } , ...args : Array < unknown > ) {
115
- const redisArgs = command . transformArguments ( ...args ) ,
128
+ let redisArgs : CommandArguments = [ ] ;
129
+ let firstKey : RedisArgument | undefined ;
130
+
131
+ if ( command . parseCommand ) {
132
+ const parser = new BasicClusterCommandParser ( resp ) ;
133
+ command . parseCommand ( parser , ...args ) ;
134
+ firstKey = parser . firstKey ;
135
+ } else {
136
+ redisArgs = command . transformArguments ( ...args ) ;
116
137
firstKey = RedisCluster . extractFirstKey (
117
138
command ,
118
139
args ,
119
140
redisArgs
120
141
) ;
142
+ }
121
143
return this . _self . addCommand (
122
144
firstKey ,
123
145
command . IS_READ_ONLY ,
@@ -128,17 +150,29 @@ export default class RedisClusterMultiCommand<REPLIES = []> {
128
150
}
129
151
130
152
static #createFunctionCommand( name : string , fn : RedisFunction , resp : RespVersions ) {
131
- const prefix = functionArgumentsPrefix ( name , fn ) ,
132
- transformReply = getTransformReply ( fn , resp ) ;
153
+ const prefix = functionArgumentsPrefix ( name , fn ) ;
154
+ const transformReply = getTransformReply ( fn , resp ) ;
155
+
133
156
return function ( this : { _self : RedisClusterMultiCommand } , ...args : Array < unknown > ) {
134
- const fnArgs = fn . transformArguments ( ...args ) ,
135
- redisArgs : CommandArguments = prefix . concat ( fnArgs ) ,
157
+ let fnArgs : CommandArguments = [ ] ;
158
+ let firstKey : RedisArgument | undefined ;
159
+
160
+ if ( fn . parseCommand ) {
161
+ const parser = new BasicClusterCommandParser ( resp ) ;
162
+ fn . parseCommand ( parser , ...args ) ;
163
+ firstKey = parser . firstKey ;
164
+ } else {
165
+ fnArgs = fn . transformArguments ( ...args ) ;
136
166
firstKey = RedisCluster . extractFirstKey (
137
167
fn ,
138
168
args ,
139
169
fnArgs
140
170
) ;
171
+ }
172
+
173
+ const redisArgs : CommandArguments = prefix . concat ( fnArgs ) ;
141
174
redisArgs . preserve = fnArgs . preserve ;
175
+
142
176
return this . _self . addCommand (
143
177
firstKey ,
144
178
fn . IS_READ_ONLY ,
@@ -150,21 +184,34 @@ export default class RedisClusterMultiCommand<REPLIES = []> {
150
184
151
185
static #createScriptCommand( script : RedisScript , resp : RespVersions ) {
152
186
const transformReply = getTransformReply ( script , resp ) ;
187
+
153
188
return function ( this : RedisClusterMultiCommand , ...args : Array < unknown > ) {
154
- const scriptArgs = script . transformArguments ( ...args ) ;
155
- this . #setState(
156
- RedisCluster . extractFirstKey (
189
+ let scriptArgs : CommandArguments = [ ] ;
190
+ let firstKey : RedisArgument | undefined ;
191
+
192
+ if ( script . parseCommand ) {
193
+ const parser = new BasicClusterCommandParser ( resp ) ;
194
+ script . parseCommand ( parser , ...args ) ;
195
+ firstKey = parser . firstKey ;
196
+ } else {
197
+ scriptArgs = script . transformArguments ( ...args ) ;
198
+ firstKey = RedisCluster . extractFirstKey (
157
199
script ,
158
200
args ,
159
201
scriptArgs
160
- ) ,
202
+ )
203
+ }
204
+
205
+ this . #setState(
206
+ firstKey ,
161
207
script . IS_READ_ONLY
162
208
) ;
163
209
this . #multi. addScript (
164
210
script ,
165
211
scriptArgs ,
166
212
transformReply
167
213
) ;
214
+
168
215
return this ;
169
216
} ;
170
217
}
0 commit comments