MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / info_get

Function info_get

tests/modules/infotest.c:38–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38int info_get(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, char field_type)
39{
40 if (argc != 3 && argc != 4) {
41 RedisModule_WrongArity(ctx);
42 return REDISMODULE_OK;
43 }
44 int err = REDISMODULE_OK;
45 const char *section, *field;
46 section = RedisModule_StringPtrLen(argv[1], NULL);
47 field = RedisModule_StringPtrLen(argv[2], NULL);
48 RedisModuleServerInfoData *info = RedisModule_GetServerInfo(ctx, section);
49 if (field_type=='i') {
50 long long ll = RedisModule_ServerInfoGetFieldSigned(info, field, &err);
51 if (err==REDISMODULE_OK)
52 RedisModule_ReplyWithLongLong(ctx, ll);
53 } else if (field_type=='u') {
54 unsigned long long ll = (unsigned long long)RedisModule_ServerInfoGetFieldUnsigned(info, field, &err);
55 if (err==REDISMODULE_OK)
56 RedisModule_ReplyWithLongLong(ctx, ll);
57 } else if (field_type=='d') {
58 double d = RedisModule_ServerInfoGetFieldDouble(info, field, &err);
59 if (err==REDISMODULE_OK)
60 RedisModule_ReplyWithDouble(ctx, d);
61 } else if (field_type=='c') {
62 const char *str = RedisModule_ServerInfoGetFieldC(info, field);
63 if (str)
64 RedisModule_ReplyWithCString(ctx, str);
65 } else {
66 RedisModuleString *str = RedisModule_ServerInfoGetField(ctx, info, field);
67 if (str) {
68 RedisModule_ReplyWithString(ctx, str);
69 RedisModule_FreeString(ctx, str);
70 } else
71 err=REDISMODULE_ERR;
72 }
73 if (err!=REDISMODULE_OK)
74 RedisModule_ReplyWithError(ctx, "not found");
75 RedisModule_FreeServerInfo(ctx, info);
76 return REDISMODULE_OK;
77}
78
79int info_gets(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
80 return info_get(ctx, argv, argc, 's');

Callers 5

info_getsFunction · 0.85
info_getcFunction · 0.85
info_getiFunction · 0.85
info_getuFunction · 0.85
info_getdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected