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

Function RedisGearsPy_Execute

plugins/python/redisgears_python.c:5001–5180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4999}
5000
5001int RedisGearsPy_Execute(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
5002#define ID_SIZE 40
5003 char id[ID_SIZE + 1] = {0}; // buffer to generate session id
5004
5005 int ctxFlags = RedisModule_GetContextFlags(ctx);
5006
5007 if(ctxFlags & (REDISMODULE_CTX_FLAGS_LUA|REDISMODULE_CTX_FLAGS_MULTI|REDISMODULE_CTX_FLAGS_DENY_BLOCKING)){
5008 RedisModule_ReplyWithError(ctx, "Can not run gears inside a multi exec, lua, or when blocking is not allowed");
5009 return REDISMODULE_OK;
5010 }
5011
5012 if(argc < 2){
5013 return RedisModule_WrongArity(ctx);
5014 }
5015
5016 VERIFY_CLUSTER_INITIALIZE(ctx);
5017
5018 const char* script = RedisModule_StringPtrLen(argv[1], NULL);
5019 char *sessionName = NULL;
5020 char *replaceWith = NULL;
5021 char *sessionDesc = NULL;
5022 bool isBlocking = true;
5023 bool upgrade = false;
5024 bool forceRequirementsReinstallation = false;
5025 size_t currArg = 2;
5026 for(; currArg < argc ; ++currArg) {
5027 const char* option = RedisModule_StringPtrLen(argv[currArg], NULL);
5028 if(strcasecmp(option, "UNBLOCKING") == 0){
5029 isBlocking = false;
5030 continue;
5031 }
5032 if(strcasecmp(option, "UPGRADE") == 0){
5033 upgrade = true;
5034 continue;
5035 }
5036 if(strcasecmp(option, "FORCE_REINSTALL_REQUIREMENTS") == 0){
5037 forceRequirementsReinstallation = true;
5038 continue;
5039 }
5040 if(strcasecmp(option, "REPLACE_WITH") == 0){
5041 if (++currArg >= argc) {
5042 RedisModule_ReplyWithError(ctx, "REPLACE_WITH is missing");
5043 return REDISMODULE_OK;
5044 }
5045 replaceWith = (char*)RedisModule_StringPtrLen(argv[currArg], NULL);
5046 continue;
5047 }
5048 if(strcasecmp(option, "ID") == 0){
5049 if (++currArg >= argc) {
5050 RedisModule_ReplyWithError(ctx, "ID is missing");
5051 return REDISMODULE_OK;
5052 }
5053 sessionName = (char*)RedisModule_StringPtrLen(argv[currArg], NULL);
5054 if (RedisGearsPy_VerifySessionId(sessionName) != REDISMODULE_OK) {
5055 RedisModule_ReplyWithError(ctx, "ID must be compose of: ['A'-'Z' | 'a'-'z' | '0' - '9' | '-' | '_']");
5056 return REDISMODULE_OK;
5057 }
5058 continue;

Callers 1

Calls 10

PythonSessionCtx_GetFunction · 0.85
PythonSessionCtx_FreeFunction · 0.85
PythonSessionCtx_CreateFunction · 0.85
GetPythonThreadCtxFunction · 0.85
array_lenFunction · 0.85

Tested by

no test coverage detected