@@ -181,7 +181,7 @@ static int _ScriptRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **
181181 RedisModuleString * * runkey , char const * * func_name ,
182182 long long * timeout , int * variadic ) {
183183
184- if (argc < 5 ) {
184+ if (argc < 3 ) {
185185 RAI_SetError (error , RAI_ESCRIPTRUN ,
186186 "ERR wrong number of arguments for 'AI.SCRIPTRUN' command" );
187187 return REDISMODULE_ERR ;
@@ -198,41 +198,50 @@ static int _ScriptRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **
198198 * runkey = argv [argpos ];
199199
200200 const char * arg_string = RedisModule_StringPtrLen (argv [++ argpos ], NULL );
201- if (!strcasecmp (arg_string , "TIMEOUT" ) || !strcasecmp (arg_string , "INPUTS" )) {
201+ if (!strcasecmp (arg_string , "TIMEOUT" ) || !strcasecmp (arg_string , "INPUTS" ) || ! strcasecmp ( arg_string , "OUTPUTS" ) ) {
202202 RAI_SetError (error , RAI_ESCRIPTRUN , "ERR function name not specified" );
203203 return REDISMODULE_ERR ;
204204 }
205205 * func_name = arg_string ;
206- arg_string = RedisModule_StringPtrLen (argv [++ argpos ], NULL );
207206
208- // Parse timeout arg if given and store it in timeout
209- if (!strcasecmp (arg_string , "TIMEOUT" )) {
210- if (_parseTimeout (argv [++ argpos ], error , timeout ) == REDISMODULE_ERR )
211- return REDISMODULE_ERR ;
212- arg_string = RedisModule_StringPtrLen (argv [++ argpos ], NULL );
213- }
214- if (strcasecmp (arg_string , "INPUTS" ) != 0 ) {
215- RAI_SetError (error , RAI_ESCRIPTRUN , "ERR INPUTS not specified" );
216- return REDISMODULE_ERR ;
217- }
218-
219- bool is_input = true, is_output = false;
207+ bool is_input = false;
208+ bool is_output = false;
209+ bool timeout_set = false;
220210 size_t ninputs = 0 , noutputs = 0 ;
221211 int varidic_start_pos = -1 ;
222212
223213 while (++ argpos < argc ) {
224214 arg_string = RedisModule_StringPtrLen (argv [argpos ], NULL );
215+
216+ // Parse timeout arg if given and store it in timeout
217+ if (!strcasecmp (arg_string , "TIMEOUT" ) && !timeout_set ) {
218+ if (_parseTimeout (argv [++ argpos ], error , timeout ) == REDISMODULE_ERR )
219+ return REDISMODULE_ERR ;
220+ timeout_set = true;
221+ continue ;
222+ }
223+
224+ if (!strcasecmp (arg_string , "INPUTS" ) && !is_input ) {
225+ is_input = true;
226+ is_output = false;
227+ continue ;
228+ }
225229 if (!strcasecmp (arg_string , "OUTPUTS" ) && !is_output ) {
226230 is_input = false;
227231 is_output = true;
228- } else if (!strcasecmp (arg_string , "$" )) {
232+ continue ;
233+ }
234+ if (!strcasecmp (arg_string , "$" )) {
229235 if (varidic_start_pos > -1 ) {
230236 RAI_SetError (error , RAI_ESCRIPTRUN ,
231237 "ERR Already encountered a variable size list of tensors" );
232238 return REDISMODULE_ERR ;
233239 }
234240 varidic_start_pos = ninputs ;
235- } else {
241+ continue ;
242+ }
243+ // Parse argument name
244+ {
236245 RAI_HoldString (NULL , argv [argpos ]);
237246 if (is_input ) {
238247 ninputs ++ ;
0 commit comments