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
| 7285 | * When done, it needs to be freed with RedisModule_FreeServerInfo or with the |
| 7286 | * automatic memory management mechanism if enabled. */ |
| 7287 | RedisModuleServerInfoData *RM_GetServerInfo(RedisModuleCtx *ctx, const char *section) { |
| 7288 | struct RedisModuleServerInfoData *d = (RedisModuleServerInfoData*)zmalloc(sizeof(*d)); |
| 7289 | d->rax = raxNew(); |
| 7290 | if (ctx != NULL) autoMemoryAdd(ctx,REDISMODULE_AM_INFO,d); |
| 7291 | sds info = genRedisInfoString(section); |
| 7292 | int totlines, i; |
| 7293 | sds *lines = sdssplitlen(info, sdslen(info), "\r\n", 2, &totlines); |
| 7294 | for(i=0; i<totlines; i++) { |
| 7295 | sds line = lines[i]; |
| 7296 | if (line[0]=='#') continue; |
| 7297 | char *sep = strchr(line, ':'); |
| 7298 | if (!sep) continue; |
| 7299 | unsigned char *key = (unsigned char*)line; |
| 7300 | size_t keylen = (intptr_t)sep-(intptr_t)line; |
| 7301 | sds val = sdsnewlen(sep+1,sdslen(line)-((intptr_t)sep-(intptr_t)line)-1); |
| 7302 | if (!raxTryInsert(d->rax,key,keylen,val,NULL)) |
| 7303 | sdsfree(val); |
| 7304 | } |
| 7305 | sdsfree(info); |
| 7306 | sdsfreesplitres(lines,totlines); |
| 7307 | return d; |
| 7308 | } |
| 7309 | |
| 7310 | /* Free data created with RM_GetServerInfo(). You need to pass the |
| 7311 | * context pointer 'ctx' only if the dictionary was created using the |
nothing calls this directly
no test coverage detected