MCPcopy Create free account
hub / github.com/RedisGears/RedisGears / RedisGearsPy_ImportRequirement

Function RedisGearsPy_ImportRequirement

plugins/python/redisgears_python.c:6529–6578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6527}
6528
6529static int RedisGearsPy_ImportRequirement(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
6530 VERIFY_CLUSTER_INITIALIZE(ctx);
6531
6532 Gears_Buffer* buff = Gears_BufferCreate();
6533
6534 for(size_t i = 1 ; i < argc ; i++){
6535 size_t len;
6536 const char* d = RedisModule_StringPtrLen(argv[i], &len);
6537 Gears_BufferAdd(buff, d, len);
6538 }
6539
6540 Gears_BufferReader br;
6541 Gears_BufferReaderInit(&br, buff);
6542
6543 char* err = NULL;
6544 PythonRequirementCtx* req = PythonRequirement_Deserialize(&br, &err);
6545 if(!req){
6546 if(!err){
6547 err = RG_STRDUP("Failed deserialize requirement");
6548 }
6549 RedisModule_ReplyWithError(ctx, err);
6550 RG_FREE(err);
6551 Gears_BufferFree(buff);
6552 return REDISMODULE_OK;
6553 }
6554
6555 Gears_BufferFree(buff);
6556
6557 RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx, NULL, NULL, NULL, 0);
6558 PythonRequirementCtx** reqs = array_new(PythonRequirementCtx*, 1);
6559 reqs = array_append(reqs, req);
6560 ExecutionPlan* ep = RedisGearsPy_DistributeRequirements(reqs, RedisGearsPy_DoneImportRequirement, bc, &err);
6561 if(!ep){
6562 // error here leave us in a state where we have the requirement but others
6563 // do not, user will see the error and will have to retry.
6564 if(!err){
6565 err = RG_STRDUP("Failed create distribute requirements execution on rg.importreq");
6566 }
6567 RedisModule_AbortBlock(bc);
6568 RedisModule_ReplyWithError(ctx, err);
6569 RG_FREE(err);
6570 }
6571
6572 // We are holding a shared ref to the requirement, we need to free it.
6573 // Notice that this will not cause the requirement to be freed.
6574 PythonRequirementCtx_Free(req);
6575 array_free(reqs);
6576
6577 return REDISMODULE_OK;
6578}
6579
6580static int RedisGearsPy_ExportRequirement(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
6581 if(argc != 2){

Callers

nothing calls this directly

Calls 7

Gears_BufferAddFunction · 0.85
Gears_BufferReaderInitFunction · 0.85
Gears_BufferFreeFunction · 0.85
array_freeFunction · 0.85

Tested by

no test coverage detected