@@ -42,25 +42,28 @@ torch::IValue IValueFromRedisReply(RedisModuleCallReply *reply){
4242}
4343
4444torch::IValue redisExecute (std::string fn_name, std::vector<std::string> args ) {
45- RedisModuleCtx* ctx = RedisModule_GetThreadSafeContext (NULL );
46- size_t len = args.size ();
47- RedisModuleString* arguments[len];
48- len = 0 ;
49- for (std::vector<std::string>::iterator it = args.begin (); it != args.end (); it++) {
50- const std::string arg = *it;
51- const char * str = arg.c_str ();
52- arguments[len++] = RedisModule_CreateString (ctx, str, strlen (str));
53- }
45+ RedisModuleCtx* ctx = RedisModule_GetThreadSafeContext (NULL );
46+ RedisModule_ThreadSafeContextLock (ctx);
47+ size_t len = args.size ();
48+ RedisModuleString* arguments[len];
49+ len = 0 ;
50+ for (std::vector<std::string>::iterator it = args.begin (); it != args.end (); it++) {
51+ const std::string arg = *it;
52+ const char * str = arg.c_str ();
53+ arguments[len++] = RedisModule_CreateString (ctx, str, strlen (str));
54+ }
5455
55- RedisModuleCallReply *reply = RedisModule_Call (ctx, fn_name.c_str (), " v" , arguments, len);
56- // RedisValue value = RedisValue::fromRedisReply(RedisModule_Call(ctx, fn_name.c_str(), "v", arguments, len));
57- torch::IValue value = IValueFromRedisReply (reply);
58- RedisModule_FreeThreadSafeContext (ctx);
59- RedisModule_FreeCallReply (reply);
60- return value;
56+ RedisModuleCallReply *reply = RedisModule_Call (ctx, fn_name.c_str (), " !v" , arguments, len);
57+ RedisModule_ThreadSafeContextUnlock (ctx);
58+ torch::IValue value = IValueFromRedisReply (reply);
59+ RedisModule_FreeThreadSafeContext (ctx);
60+ RedisModule_FreeCallReply (reply);
61+ for (int i= 0 ; i < len; i++){
62+ RedisModule_FreeString (NULL , arguments[i]);
63+ }
64+ return value;
6165}
6266
63-
6467torch::List<torch::IValue> asList (torch::IValue v) {
6568 return v.toList ();
66- }
69+ }
0 commit comments