Hiredis waiting for message
- by Vivek Goel
I am using hiredis C library to connect to redis server. I am not able to figure out how to wait for new messages after subscribing to new message.
My code look like:
signal(SIGPIPE, SIG_IGN );
struct event_base *base = event_base_new();
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}
redisLibeventAttach(c, base);
redisAsyncSetConnectCallback(c, connectCallback);
redisAsyncSetDisconnectCallback(c, disconnectCallback);
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc - 1],
strlen(argv[argc - 1]));
redisAsyncCommand(c, getCallback, (char*) "end-1", "GET key");
redisAsyncCommand(c, getCallback, (char*) "end-1", "SUBSCRIBE foo");
Now how to tell hiredis to wait for message on channel ?