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