Gaming, Linux, Programming by day. Atheism and tolerance by night. Sci-Fi television all hours of the day.
Running this program, you can receive messages using Redis’ pub/sub capabilities.
I couldn’t believe how easy this was.
#include <hiredis/hiredis.h>
#include <string>
#include <iostream>
int main()
{
void* reply_alloc;
/* You can change this to listen to a remote channel port if the server is
* configured to accept connections on that port.
*/
redisContext* redis= redisConnect("localhost",6379);
/* You can subscribe to any number of channels with
* this command, and all messages
* published by this channel will appear in your CLI.
*/
reply_alloc = (void*)redisCommand(redis,"subscribe foo");
while (redisGetReply(redis,&reply_alloc)==REDIS_OK)
{
redisReply* reply = (redisReply*)reply_alloc;
if (reply->type == REDIS_REPLY_ARRAY)
{
std::string message = reply->element[2]->str;
std::cout << message << std::endl;
}
}
}
So easy! I love Redis so much!
Design by Simon Fletcher. Powered by Tumblr.
© Copyright 2010