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

Function RedisGearsPy_DumpSessions

plugins/python/redisgears_python.c:6358–6430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6356}
6357
6358static int RedisGearsPy_DumpSessions(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
6359 pthread_mutex_lock(&PySessionsLock);
6360 int verbose = 0;
6361 int ts = 0;
6362 int tmp = 0;
6363 if (argc > 1) {
6364 // dump sessions by name
6365 size_t currArg = 1;
6366 for(; currArg < argc ; ++currArg) {
6367 const char* option = RedisModule_StringPtrLen(argv[currArg], NULL);
6368 if(strcasecmp(option, "VERBOSE") == 0){
6369 verbose = 1;
6370 continue;
6371 }
6372 if(strcasecmp(option, "DEAD") == 0){
6373 ts = 1;
6374 continue;
6375 }
6376 break;
6377 }
6378
6379 if (currArg < argc) {
6380 const char* lastOption = RedisModule_StringPtrLen(argv[currArg++], NULL);
6381 if(strcasecmp(lastOption, "SESSIONS") == 0){
6382 RedisModule_ReplyWithArray(ctx, argc - currArg);
6383 for (size_t i = currArg ; i < argc ; ++i) {
6384 const char* sessionName = RedisModule_StringPtrLen(argv[i], NULL);
6385 // we can fetch session directly because we take the PySessionsLock
6386 PythonSessionCtx* s = RedisModule_DictGetC(SessionsDict, (char*)sessionName, strlen(sessionName), NULL);
6387 if (!s) {
6388 char* msg;
6389 RedisGears_ASprintf(&msg, "Session %s does not exists", sessionName);
6390 RedisModule_ReplyWithCString(ctx, msg);
6391 RG_FREE(msg);
6392 } else {
6393 RedisGearsPy_DumpSingleSession(ctx, s, verbose);
6394 }
6395 }
6396 } else {
6397 char* msg;
6398 RedisGears_ASprintf(&msg, "Unknown option %s", lastOption);
6399 RedisModule_ReplyWithError(ctx, msg);
6400 RG_FREE(msg);
6401 }
6402 pthread_mutex_unlock(&PySessionsLock);
6403 return REDISMODULE_OK;
6404 }
6405 if (ts) {
6406 RedisModule_ReplyWithArray(ctx, Gears_listLength(DeadSessionsList));
6407 Gears_listIter *iter = Gears_listGetIterator(DeadSessionsList, AL_START_HEAD);
6408 Gears_listNode *n = NULL;
6409 while((n = Gears_listNext(iter))) {
6410 PythonSessionCtx* s = Gears_listNodeValue(n);
6411 RedisGearsPy_DumpSingleSession(ctx, s, verbose);
6412 }
6413 Gears_listReleaseIterator(iter);
6414 pthread_mutex_unlock(&PySessionsLock);
6415 return REDISMODULE_OK;

Callers

nothing calls this directly

Calls 4

Gears_listGetIteratorFunction · 0.85
Gears_listNextFunction · 0.85

Tested by

no test coverage detected