Created
April 19, 2011 13:07
-
-
Save pashields/927538 to your computer and use it in GitHub Desktop.
This attempts to show the failure of redis' punsubscribe cmd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include "hiredis.h" | |
int main(void) { | |
int ppid = fork(); | |
if (ppid == 0) { | |
redisContext *c; | |
redisReply *reply; | |
c = redisConnect((char*)"127.0.0.1", 6379); | |
if (c->err) { | |
printf("Connection error: %s\n", c->errstr); | |
exit(1); | |
} | |
printf("Subscribing\n"); | |
reply = redisCommand(c,"SUBSCRIBE foo"); | |
freeReplyObject(reply); | |
// Should get bar | |
redisGetReply(c, (void**)&reply); | |
printf("Reply is: %s\n", reply->element[2]->str); | |
freeReplyObject(reply); | |
printf("Unsubscribing\n"); | |
reply = redisCommand(c,"PUNSUBSCRIBE *"); | |
printf("Unsubscribed from %s\n", reply->element[1]->str); | |
freeReplyObject(reply); | |
// Really, we should hang here, but we'll get zip | |
redisGetReply(c, (void**)&reply); | |
printf("Reply is: %s\n", reply->element[2]->str); | |
freeReplyObject(reply); | |
exit(0); | |
} | |
else { | |
redisContext *c; | |
redisReply *reply; | |
c = redisConnect((char*)"127.0.0.1", 6379); | |
if (c->err) { | |
printf("Connection error: %s\n", c->errstr); | |
exit(1); | |
} | |
// I expect this to go through | |
sleep(1); | |
printf("Publishing"); | |
reply = redisCommand(c, "PUBLISH foo bar"); | |
freeReplyObject(reply); | |
// This should come in after the unsubscribe (monitor can confirm this) | |
sleep(1); | |
printf("Publishing"); | |
reply = redisCommand(c, "PUBLISH foo zip"); | |
freeReplyObject(reply); | |
} | |
wait(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment