1
1
import COMMANDS from '../commands' ;
2
2
import RedisMultiCommand , { MULTI_REPLY , MultiReply , MultiReplyType , RedisMultiQueuedCommand } from '../multi-command' ;
3
- import { ReplyWithTypeMapping , CommandReply , Command , CommandArguments , CommanderConfig , RedisFunctions , RedisModules , RedisScripts , RespVersions , RedisScript , RedisFunction , TypeMapping , RedisArgument } from '../RESP/types' ;
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 { BasicCommandParser } from '../client/parser' ;
6
6
import { Tail } from '../commands/generic-transformers' ;
@@ -95,44 +95,48 @@ export default class RedisClusterMultiCommand<REPLIES = []> {
95
95
static #createCommand( command : Command , resp : RespVersions ) {
96
96
const transformReply = getTransformReply ( command , resp ) ;
97
97
98
- return function ( this : RedisClusterMultiCommand , ...args : Array < unknown > ) : RedisClusterMultiCommand {
98
+ return function ( this : RedisClusterMultiCommand , ...args : Array < unknown > ) {
99
99
const parser = new BasicCommandParser ( ) ;
100
100
command . parseCommand ( parser , ...args ) ;
101
101
102
102
const redisArgs : CommandArguments = parser . redisArgs ;
103
103
redisArgs . preserve = parser . preserve ;
104
104
const firstKey = parser . firstKey ;
105
-
106
- this . #setState( firstKey , command . IS_READ_ONLY ) ;
107
- this . #multi. addCommand ( redisArgs , transformReply ) ;
108
-
109
- return this ;
105
+
106
+ return this . addCommand (
107
+ firstKey ,
108
+ command . IS_READ_ONLY ,
109
+ redisArgs ,
110
+ transformReply
111
+ ) ;
110
112
} ;
111
113
}
112
114
113
115
static #createModuleCommand( command : Command , resp : RespVersions ) {
114
116
const transformReply = getTransformReply ( command , resp ) ;
115
117
116
- return function ( this : { _self : RedisClusterMultiCommand } , ...args : Array < unknown > ) : RedisClusterMultiCommand {
118
+ return function ( this : { _self : RedisClusterMultiCommand } , ...args : Array < unknown > ) {
117
119
const parser = new BasicCommandParser ( ) ;
118
120
command . parseCommand ( parser , ...args ) ;
119
121
120
122
const redisArgs : CommandArguments = parser . redisArgs ;
121
123
redisArgs . preserve = parser . preserve ;
122
124
const firstKey = parser . firstKey ;
123
125
124
- this . _self . #setState( firstKey , command . IS_READ_ONLY ) ;
125
- this . _self . #multi. addCommand ( redisArgs , transformReply ) ;
126
-
127
- return this . _self ;
126
+ return this . _self . addCommand (
127
+ firstKey ,
128
+ command . IS_READ_ONLY ,
129
+ redisArgs ,
130
+ transformReply
131
+ ) ;
128
132
} ;
129
133
}
130
134
131
135
static #createFunctionCommand( name : string , fn : RedisFunction , resp : RespVersions ) {
132
136
const prefix = functionArgumentsPrefix ( name , fn ) ;
133
137
const transformReply = getTransformReply ( fn , resp ) ;
134
138
135
- return function ( this : { _self : RedisClusterMultiCommand } , ...args : Array < unknown > ) : RedisClusterMultiCommand {
139
+ return function ( this : { _self : RedisClusterMultiCommand } , ...args : Array < unknown > ) {
136
140
const parser = new BasicCommandParser ( ) ;
137
141
parser . push ( ...prefix ) ;
138
142
fn . parseCommand ( parser , ...args ) ;
@@ -141,28 +145,33 @@ export default class RedisClusterMultiCommand<REPLIES = []> {
141
145
redisArgs . preserve = parser . preserve ;
142
146
const firstKey = parser . firstKey ;
143
147
144
- this . _self . #setState( firstKey , fn . IS_READ_ONLY ) ;
145
- this . _self . #multi. addCommand ( redisArgs , transformReply ) ;
146
-
147
- return this . _self ;
148
+ return this . _self . addCommand (
149
+ firstKey ,
150
+ fn . IS_READ_ONLY ,
151
+ redisArgs ,
152
+ transformReply
153
+ ) ;
148
154
} ;
149
155
}
150
156
151
157
static #createScriptCommand( script : RedisScript , resp : RespVersions ) {
152
158
const transformReply = getTransformReply ( script , resp ) ;
153
159
154
- return function ( this : RedisClusterMultiCommand , ...args : Array < unknown > ) : RedisClusterMultiCommand {
160
+ return function ( this : RedisClusterMultiCommand , ...args : Array < unknown > ) {
155
161
const parser = new BasicCommandParser ( ) ;
156
162
script . parseCommand ( parser , ...args ) ;
157
163
158
164
const scriptArgs : CommandArguments = parser . redisArgs ;
159
165
scriptArgs . preserve = parser . preserve ;
160
166
const firstKey = parser . firstKey ;
161
167
162
- this . #setState( firstKey , script . IS_READ_ONLY ) ;
163
- this . #multi. addScript ( script , scriptArgs , transformReply ) ;
164
-
165
- return this ;
168
+ return this . #addScript(
169
+ firstKey ,
170
+ script . IS_READ_ONLY ,
171
+ script ,
172
+ scriptArgs ,
173
+ transformReply
174
+ ) ;
166
175
} ;
167
176
}
168
177
@@ -183,7 +192,7 @@ export default class RedisClusterMultiCommand<REPLIES = []> {
183
192
} ) ;
184
193
}
185
194
186
- readonly #multi: RedisMultiCommand ;
195
+ readonly #multi: RedisMultiCommand
187
196
188
197
readonly #executeMulti: ClusterMultiExecute ;
189
198
readonly #executePipeline: ClusterMultiExecute ;
@@ -210,6 +219,30 @@ export default class RedisClusterMultiCommand<REPLIES = []> {
210
219
this . #isReadonly &&= isReadonly ;
211
220
}
212
221
222
+ addCommand (
223
+ firstKey : RedisArgument | undefined ,
224
+ isReadonly : boolean | undefined ,
225
+ args : CommandArguments ,
226
+ transformReply ?: TransformReply
227
+ ) {
228
+ this . #setState( firstKey , isReadonly ) ;
229
+ this . #multi. addCommand ( args , transformReply ) ;
230
+ return this ;
231
+ }
232
+
233
+ #addScript(
234
+ firstKey : RedisArgument | undefined ,
235
+ isReadonly : boolean | undefined ,
236
+ script : RedisScript ,
237
+ args : CommandArguments ,
238
+ transformReply ?: TransformReply
239
+ ) {
240
+ this . #setState( firstKey , isReadonly ) ;
241
+ this . #multi. addScript ( script , args , transformReply ) ;
242
+
243
+ return this ;
244
+ }
245
+
213
246
async exec < T extends MultiReply = MULTI_REPLY [ 'GENERIC' ] > ( execAsPipeline = false ) {
214
247
if ( execAsPipeline ) return this . execAsPipeline < T > ( ) ;
215
248
0 commit comments