Hiredis waiting for message

Posted by Vivek Goel on Stack Overflow See other posts from Stack Overflow or by Vivek Goel
Published on 2013-04-25T11:35:32Z Indexed on 2013/10/22 3:55 UTC
Read the original article Hit count: 209

Filed under:
|

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 ?

© Stack Overflow or respective owner

Related posts about redis

Related posts about hiredis