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

Function RedisGearsPy_ExportRequirement

plugins/python/redisgears_python.c:6580–6633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6578}
6579
6580static int RedisGearsPy_ExportRequirement(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
6581 if(argc != 2){
6582 return RedisModule_WrongArity(ctx);
6583 }
6584
6585 const char* reqName = RedisModule_StringPtrLen(argv[1], NULL);
6586
6587 // Notice that this increase the requirement ref count so we must free it as the end.
6588 PythonRequirementCtx* req = PythonRequirementCtx_Get(reqName);
6589
6590 if(!req){
6591 RedisModule_ReplyWithError(ctx, "requirement does not exists");
6592 return REDISMODULE_OK;
6593 }
6594
6595 Gears_Buffer* buff = Gears_BufferCreate();
6596 Gears_BufferWriter bw;
6597 Gears_BufferWriterInit(&bw, buff);
6598 char* err = NULL;
6599 if(PythonRequirement_Serialize(req, &bw, &err) != REDISMODULE_OK){
6600 PythonRequirementCtx_Free(req);
6601 Gears_BufferFree(buff);
6602 if(!err){
6603 err = RG_STRDUP("Failed serializing requirement");
6604 }
6605 RedisModule_ReplyWithError(ctx, err);
6606 RG_FREE(err);
6607 return REDISMODULE_OK;
6608 }
6609
6610 RedisModule_ReplyWithArray(ctx, 2);
6611
6612 RedisGearsPy_SendReqMetaData(ctx, req);
6613
6614 RedisModule_ReplyWithArray(ctx, REDISMODULE_POSTPONED_ARRAY_LEN);
6615
6616#define BULK_LEN (1024*1024*10); // 10 MB
6617 int maxBulKLen = BULK_LEN;
6618
6619 size_t currPos = 0 ;
6620 size_t arrayLen = 0;
6621 while(currPos < buff->size){
6622 size_t currLen = MIN(maxBulKLen, (buff->size - currPos));
6623 RedisModule_ReplyWithStringBuffer(ctx, buff->buff + currPos, currLen);
6624 currPos += currLen;
6625 ++arrayLen;
6626 }
6627
6628 RedisModule_ReplySetArrayLength(ctx, arrayLen);
6629
6630 Gears_BufferFree(buff);
6631 PythonRequirementCtx_Free(req);
6632 return REDISMODULE_OK;
6633}
6634
6635static int RedisGearsPy_Stats(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
6636 RedisModule_ReplyWithArray(ctx, 6);

Callers

nothing calls this directly

Calls 6

PythonRequirementCtx_GetFunction · 0.85
Gears_BufferWriterInitFunction · 0.85
Gears_BufferFreeFunction · 0.85

Tested by

no test coverage detected