@@ -164,7 +164,7 @@ static int _ScriptRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **
164164 RedisModuleString * * runkey , char const * * func_name ,
165165 long long * timeout , int * variadic ) {
166166
167- if (argc < 5 ) {
167+ if (argc < 3 ) {
168168 RAI_SetError (error , RAI_ESCRIPTRUN ,
169169 "ERR wrong number of arguments for 'AI.SCRIPTRUN' command" );
170170 return REDISMODULE_ERR ;
@@ -181,49 +181,83 @@ static int _ScriptRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **
181181 * runkey = argv [argpos ];
182182
183183 const char * arg_string = RedisModule_StringPtrLen (argv [++ argpos ], NULL );
184- if (!strcasecmp (arg_string , "TIMEOUT" ) || !strcasecmp (arg_string , "INPUTS" )) {
184+ if (!strcasecmp (arg_string , "TIMEOUT" ) || !strcasecmp (arg_string , "INPUTS" ) ||
185+ !strcasecmp (arg_string , "OUTPUTS" )) {
185186 RAI_SetError (error , RAI_ESCRIPTRUN , "ERR function name not specified" );
186187 return REDISMODULE_ERR ;
187188 }
188189 * func_name = arg_string ;
189- arg_string = RedisModule_StringPtrLen (argv [++ argpos ], NULL );
190190
191- // Parse timeout arg if given and store it in timeout
192- if (!strcasecmp (arg_string , "TIMEOUT" )) {
193- if (_parseTimeout (argv [++ argpos ], error , timeout ) == REDISMODULE_ERR )
194- return REDISMODULE_ERR ;
195- arg_string = RedisModule_StringPtrLen (argv [++ argpos ], NULL );
196- }
197- if (strcasecmp (arg_string , "INPUTS" ) != 0 ) {
198- RAI_SetError (error , RAI_ESCRIPTRUN , "ERR INPUTS not specified" );
199- return REDISMODULE_ERR ;
200- }
201-
202- bool is_input = true, is_output = false;
191+ bool is_input = false;
192+ bool is_output = false;
193+ bool timeout_set = false;
194+ bool inputs_done = false;
203195 size_t ninputs = 0 , noutputs = 0 ;
204196 int varidic_start_pos = -1 ;
205197
206198 while (++ argpos < argc ) {
207199 arg_string = RedisModule_StringPtrLen (argv [argpos ], NULL );
208- if (!strcasecmp (arg_string , "OUTPUTS" ) && !is_output ) {
200+
201+ // Parse timeout arg if given and store it in timeout
202+ if (!strcasecmp (arg_string , "TIMEOUT" ) && !timeout_set ) {
203+ if (_parseTimeout (argv [++ argpos ], error , timeout ) == REDISMODULE_ERR )
204+ return REDISMODULE_ERR ;
205+ timeout_set = true;
206+ continue ;
207+ }
208+
209+ if (!strcasecmp (arg_string , "INPUTS" )) {
210+ if (inputs_done ) {
211+ RAI_SetError (error , RAI_ESCRIPTRUN ,
212+ "ERR Already encountered an INPUTS section in SCRIPTRUN" );
213+ return REDISMODULE_ERR ;
214+ }
215+ if (is_input ) {
216+ RAI_SetError (error , RAI_ESCRIPTRUN ,
217+ "ERR Already encountered an INPUTS keyword in SCRIPTRUN" );
218+ return REDISMODULE_ERR ;
219+ }
220+ is_input = true;
221+ is_output = false;
222+ continue ;
223+ }
224+ if (!strcasecmp (arg_string , "OUTPUTS" )) {
225+ if (is_output ) {
226+ RAI_SetError (error , RAI_ESCRIPTRUN ,
227+ "ERR Already encountered an OUTPUTS keyword in SCRIPTRUN" );
228+ return REDISMODULE_ERR ;
229+ }
209230 is_input = false;
210231 is_output = true;
211- } else if (!strcasecmp (arg_string , "$" )) {
232+ inputs_done = true;
233+ continue ;
234+ }
235+ if (!strcasecmp (arg_string , "$" )) {
236+ if (!is_input ) {
237+ RAI_SetError (
238+ error , RAI_ESCRIPTRUN ,
239+ "ERR Encountered a variable size list of tensors outside of input section" );
240+ return REDISMODULE_ERR ;
241+ }
212242 if (varidic_start_pos > -1 ) {
213243 RAI_SetError (error , RAI_ESCRIPTRUN ,
214244 "ERR Already encountered a variable size list of tensors" );
215245 return REDISMODULE_ERR ;
216246 }
217247 varidic_start_pos = ninputs ;
248+ continue ;
249+ }
250+ // Parse argument name
251+ RAI_HoldString (NULL , argv [argpos ]);
252+ if (is_input ) {
253+ ninputs ++ ;
254+ * inkeys = array_append (* inkeys , argv [argpos ]);
255+ } else if (is_output ) {
256+ noutputs ++ ;
257+ * outkeys = array_append (* outkeys , argv [argpos ]);
218258 } else {
219- RAI_HoldString (NULL , argv [argpos ]);
220- if (is_input ) {
221- ninputs ++ ;
222- * inkeys = array_append (* inkeys , argv [argpos ]);
223- } else {
224- noutputs ++ ;
225- * outkeys = array_append (* outkeys , argv [argpos ]);
226- }
259+ RAI_SetError (error , RAI_ESCRIPTRUN , "ERR Unrecongnized parameter to SCRIPTRUN" );
260+ return REDISMODULE_ERR ;
227261 }
228262 }
229263 * variadic = varidic_start_pos ;
0 commit comments