2
我使用hiredis C庫連接到redis服務器。在訂閱新消息後,我無法弄清楚如何等待新消息。Hiredis等待消息
我的代碼如下所示:
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");
現在該怎麼告訴hiredis等待與渠道的消息?