-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathreg-redis.c
More file actions
34 lines (29 loc) · 1.05 KB
/
reg-redis.c
File metadata and controls
34 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "hiredis/hiredis.h"
#include "hiredis/async.h"
#include "hiredis/adapters/libev.h"
#include "reg-ev.h"
redisAsyncContext *redisCtx;
static void connectHandler(const redisAsyncContext *redisCtx, int status)
{
if (status != REDIS_OK) printf("Error: %s\n", redisCtx->errstr);
else printf("Connected to redis...\n");
}
static void disconnectHandler(const redisAsyncContext *redisCtx, int status)
{
if (status != REDIS_OK) printf("Error: %s\n", redisCtx->errstr);
else printf("Disconnected to redis...\n");
}
bool registerRedis()
{
signal(SIGPIPE, SIG_IGN);
redisCtx = redisAsyncConnect("127.0.0.1", 6379);
if (redisCtx->err) {
printf("Error: %s\n", redisCtx->errstr);
return false;
}
redisLibevAttach(EV_DEFAULT_ redisCtx);
redisAsyncSetConnectCallback(redisCtx, connectHandler);
redisAsyncSetDisconnectCallback(redisCtx, disconnectHandler);
return true;
}
/* static void getHandler(redisAsyncContext *redisCtx, void *r, void *privdata); */