MCPcopy Create free account
hub / github.com/F-Stack/f-stack / RM_GetServerInfo

Function RM_GetServerInfo

app/redis-6.2.6/src/module.c:7095–7116  ·  view source on GitHub ↗

Get information about the server similar to the one that returns from the * INFO command. This function takes an optional 'section' argument that may * be NULL. The return value holds the output and can be used with * RedisModule_ServerInfoGetField and alike to get the individual fields. * When done, it needs to be freed with RedisModule_FreeServerInfo or with the * automatic memory managemen

Source from the content-addressed store, hash-verified

7093 * When done, it needs to be freed with RedisModule_FreeServerInfo or with the
7094 * automatic memory management mechanism if enabled. */
7095RedisModuleServerInfoData *RM_GetServerInfo(RedisModuleCtx *ctx, const char *section) {
7096 struct RedisModuleServerInfoData *d = zmalloc(sizeof(*d));
7097 d->rax = raxNew();
7098 if (ctx != NULL) autoMemoryAdd(ctx,REDISMODULE_AM_INFO,d);
7099 sds info = genRedisInfoString(section);
7100 int totlines, i;
7101 sds *lines = sdssplitlen(info, sdslen(info), "\r\n", 2, &totlines);
7102 for(i=0; i<totlines; i++) {
7103 sds line = lines[i];
7104 if (line[0]=='#') continue;
7105 char *sep = strchr(line, ':');
7106 if (!sep) continue;
7107 unsigned char *key = (unsigned char*)line;
7108 size_t keylen = (intptr_t)sep-(intptr_t)line;
7109 sds val = sdsnewlen(sep+1,sdslen(line)-((intptr_t)sep-(intptr_t)line)-1);
7110 if (!raxTryInsert(d->rax,key,keylen,val,NULL))
7111 sdsfree(val);
7112 }
7113 sdsfree(info);
7114 sdsfreesplitres(lines,totlines);
7115 return d;
7116}
7117
7118/* Free data created with RM_GetServerInfo(). You need to pass the
7119 * context pointer 'ctx' only if the dictionary was created using the

Callers

nothing calls this directly

Calls 11

zmallocFunction · 0.85
raxNewFunction · 0.85
autoMemoryAddFunction · 0.85
genRedisInfoStringFunction · 0.85
sdssplitlenFunction · 0.85
sdslenFunction · 0.85
strchrFunction · 0.85
sdsnewlenFunction · 0.85
raxTryInsertFunction · 0.85
sdsfreeFunction · 0.85
sdsfreesplitresFunction · 0.85

Tested by

no test coverage detected