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
| 7093 | * When done, it needs to be freed with RedisModule_FreeServerInfo or with the |
| 7094 | * automatic memory management mechanism if enabled. */ |
| 7095 | RedisModuleServerInfoData *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 |
nothing calls this directly
no test coverage detected