You can check how I do it in the "sentinel.c" code in the Redis
distribution, but I agree that this should be more clearly documented.
In short, to subscribe to "ILOVEUPPERCASE" channel:
void myCallBackFunction(redisAsyncContext *c, void *reply, void *privdata) {
redisReply *r;
if (r == NULL) return;
/* Sanity check in the reply we expect, so that the code that follows
* can avoid to check for details. */
if (r->type != REDIS_REPLY_ARRAY ||
r->elements != 3 ||
r->element[0]->type != REDIS_REPLY_STRING ||
r->element[1]->type != REDIS_REPLY_STRING ||
r->element[2]->type != REDIS_REPLY_STRING ||
strcmp(r->element[0]->str,"message") != 0) return;
printf("%s\n",r->element[2]->str);
}
retval = redisAsyncCommand(context, myCallBackFunction, NULL,
"SUBSCRIBE %s", "ILOVEUPPERCASE");
Cheers,
Salvatore
On Wed, Nov 28, 2012 at 10:30 AM, MSP <
mohitb...@gmail.com> wrote:
> I want to listen for messages continuously on a channel (PUB/SUB Redis)
> using C launguage . I am using hiredis library.
> Can anyone suggest the way to achieve this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/redis-db/-/0ZyiVsVwet0J.
> To post to this group, send email to
redi...@googlegroups.com.
> To unsubscribe from this group, send email to
>
redis-db+u...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/redis-db?hl=en.
--
Salvatore 'antirez' Sanfilippo
open source developer - VMware
http://invece.org
Beauty is more important in computing than anywhere else in technology
because software is so complicated. Beauty is the ultimate defence
against complexity.
— David Gelernter