How to use Pub/sub with hiredis in C++?

Programming/Redis 2016. 9. 29. 14:06 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

example for pub/sub



https://github.com/redis/hiredis/issues/55 aluiken commented on Mar 2, 2012




void onMessage(redisAsyncContext *c, void *reply, void *privdata) {
    redisReply *r = reply;
    if (reply == NULL) return;

    if (r->type == REDIS_REPLY_ARRAY) {
        for (int j = 0; j < r->elements; j++) {
            printf("%u) %s\n", j, r->element[j]->str);
        }
    }
}

int main (int argc, char **argv) {
    signal(SIGPIPE, SIG_IGN);
    struct event_base *base = event_base_new();

    redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
    if (c->err) {
        printf("error: %s\n", c->errstr);
        return 1;
    }

    redisLibeventAttach(c, base);
    redisAsyncCommand(c, onMessage, NULL, "SUBSCRIBE testtopic");
    event_base_dispatch(base);
    return 0;
}

'Programming > Redis' 카테고리의 다른 글

Redis Client Connect Test  (0) 2016.10.26
Hiredis Subscribe/Publish with CWinThread  (0) 2016.10.05
hiredis fatal error C1853:  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28
Windows7 Redis 설치 및 실행  (0) 2016.09.27