@@ -718,101 +718,14 @@ int RedisAI_ScriptDel_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
718
718
* AI.SCRIPTSET script_key device [TAG tag] SOURCE script_source
719
719
*/
720
720
int RedisAI_ScriptSet_RedisCommand (RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
721
- if (argc != 5 && argc != 7 )
722
- return RedisModule_WrongArity (ctx );
723
-
724
- ArgsCursor ac ;
725
- ArgsCursor_InitRString (& ac , argv + 1 , argc - 1 );
726
-
727
- RedisModuleString * keystr ;
728
- AC_GetRString (& ac , & keystr , 0 );
729
-
730
- const char * devicestr ;
731
- AC_GetString (& ac , & devicestr , NULL , 0 );
732
-
733
- RedisModuleString * tag = NULL ;
734
- if (AC_AdvanceIfMatch (& ac , "TAG" )) {
735
- AC_GetRString (& ac , & tag , 0 );
736
- }
737
-
738
- if (AC_IsAtEnd (& ac )) {
739
- return RedisModule_ReplyWithError (ctx , "ERR Insufficient arguments, missing script SOURCE" );
740
- }
741
-
742
- size_t scriptlen ;
743
- const char * scriptdef = NULL ;
744
-
745
- if (AC_AdvanceIfMatch (& ac , "SOURCE" )) {
746
- AC_GetString (& ac , & scriptdef , & scriptlen , 0 );
747
- }
748
-
749
- if (scriptdef == NULL ) {
750
- return RedisModule_ReplyWithError (ctx , "ERR Insufficient arguments, missing script SOURCE" );
751
- }
752
-
753
- RAI_Script * script = NULL ;
754
-
755
- RAI_Error err = {0 };
756
- script = RAI_ScriptCreate (devicestr , tag , scriptdef , & err );
757
-
758
- if (err .code == RAI_EBACKENDNOTLOADED ) {
759
- RedisModule_Log (ctx , "warning" ,
760
- "Backend TORCH not loaded, will try loading default backend" );
761
- int ret = RAI_LoadDefaultBackend (ctx , RAI_BACKEND_TORCH );
762
- if (ret == REDISMODULE_ERR ) {
763
- RedisModule_Log (ctx , "warning" , "Could not load TORCH default backend" );
764
- int ret = RedisModule_ReplyWithError (ctx , "ERR Could not load backend" );
765
- RAI_ClearError (& err );
766
- return ret ;
767
- }
768
- RAI_ClearError (& err );
769
- script = RAI_ScriptCreate (devicestr , tag , scriptdef , & err );
770
- }
771
-
772
- if (err .code != RAI_OK ) {
773
- #ifdef RAI_PRINT_BACKEND_ERRORS
774
- printf ("ERR: %s\n" , err .detail );
775
- #endif
776
- int ret = RedisModule_ReplyWithError (ctx , err .detail_oneline );
777
- RAI_ClearError (& err );
778
- return ret ;
779
- }
780
-
781
- if (!RunQueue_IsExists (devicestr )) {
782
- RunQueueInfo * run_queue_info = RunQueue_Create (devicestr );
783
- if (run_queue_info == NULL ) {
784
- RAI_ScriptFree (script , & err );
785
- RedisModule_ReplyWithError (ctx , "ERR Could not initialize queue on requested device" );
786
- }
787
- }
788
-
789
- RedisModuleKey * key = RedisModule_OpenKey (ctx , keystr , REDISMODULE_READ | REDISMODULE_WRITE );
790
- int type = RedisModule_KeyType (key );
791
- if (type != REDISMODULE_KEYTYPE_EMPTY &&
792
- !(type == REDISMODULE_KEYTYPE_MODULE &&
793
- RedisModule_ModuleTypeGetType (key ) == RAI_ScriptRedisType ())) {
794
- RedisModule_CloseKey (key );
795
- return RedisModule_ReplyWithError (ctx , REDISMODULE_ERRORMSG_WRONGTYPE );
796
- }
797
-
798
- RedisModule_ModuleTypeSetValue (key , RAI_ScriptRedisType (), script );
799
-
800
- script -> infokey = RAI_AddStatsEntry (ctx , keystr , RAI_SCRIPT , RAI_BACKEND_TORCH , devicestr , tag );
801
-
802
- RedisModule_CloseKey (key );
803
-
804
- RedisModule_ReplyWithSimpleString (ctx , "OK" );
805
-
806
- RedisModule_ReplicateVerbatim (ctx );
807
-
808
- return REDISMODULE_OK ;
721
+ RedisModule_Log (ctx , "warning" ,
722
+ "AI.SCRIPTSET command is deprecated and will"
723
+ " not be available in future version, you can use AI.SCRIPTSTORE instead" );
724
+ return ScriptSetCommand (ctx , argv , argc );
809
725
}
810
726
811
- /*
812
- * Todo: this is temporary until we implement the new command, for testing broadcast in DMC
813
- */
814
727
int RedisAI_ScriptStore_RedisCommand (RedisModuleCtx * ctx , RedisModuleString * * argv , int argc ) {
815
- // AI.SCRIPTSET <key> <device> ENTRY_POINTS 1 ep1 SOURCE blob
728
+ // AI.SCRIPTSTORE <key> <device> ENTRY_POINTS 1 ep1 SOURCE blob
816
729
if (argc < 8 )
817
730
return RedisModule_WrongArity (ctx );
818
731
0 commit comments