Skip to content

Instantly share code, notes, and snippets.

@sysroad
Last active August 29, 2015 14:24
Show Gist options
  • Save sysroad/6d055d49fbdd29f394d6 to your computer and use it in GitHub Desktop.
Save sysroad/6d055d49fbdd29f394d6 to your computer and use it in GitHub Desktop.
redis monitoring
#include <hiredis\hiredis.h>
#include <stdio.h>
#pragma comment(lib, "hiredis.lib")
#pragma comment(lib, "Win32_Interop.lib")
#pragma comment(lib, "lua.lib")
int _tmain(int argc, _TCHAR* argv[])
{
timeval tv;
tv.tv_sec = 2;
tv.tv_usec = 0;
redisContext * pRedis = redisConnectWithTimeout("127.0.0.1", 6379, tv);
void * rep = nullptr;
if (pRedis && pRedis->err == REDIS_OK)
{
rep = redisCommand(pRedis, "monitor");
fprintf(stderr, "MONITORING: %s\n", ((redisReply*)rep)->str);
freeReplyObject(rep);
if (rep)
{
int retCode = REDIS_OK;
while (REDIS_OK == retCode)
{
retCode = redisGetReply(pRedis, &rep);
fprintf(stderr, "ERROR CODE : %d , ERROR STR : %s", pRedis->err, pRedis->errstr);
freeReplyObject(rep);
}
}
}
else if (pRedis)
{
fprintf(stderr, "ERROR : %s", pRedis->errstr);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment