2010-09-25 20:34:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-10-07 15:48:03 +00:00
|
|
|
#include <hiredis/libevent.h>
|
2010-10-10 18:51:27 +00:00
|
|
|
#include <signal.h>
|
2010-09-25 20:34:22 +00:00
|
|
|
|
2010-10-07 15:48:03 +00:00
|
|
|
void getCallback(redisContext *c, redisReply *reply, const void *privdata) {
|
|
|
|
printf("argv[%s]: %s\n", (const char*)privdata, reply->reply);
|
2010-09-25 20:34:22 +00:00
|
|
|
|
2010-10-07 15:48:03 +00:00
|
|
|
/* Disconnect after receiving the reply to GET */
|
|
|
|
redisDisconnect(c);
|
2010-09-25 20:34:22 +00:00
|
|
|
}
|
|
|
|
|
2010-10-07 15:48:03 +00:00
|
|
|
void errorCallback(redisContext *c) {
|
|
|
|
printf("Error: %s\n", c->error);
|
2010-09-25 20:34:22 +00:00
|
|
|
|
2010-10-07 15:48:03 +00:00
|
|
|
/* Clean up the context when there was an error */
|
2010-09-25 20:34:22 +00:00
|
|
|
redisFree(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv) {
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2010-10-11 16:26:38 +00:00
|
|
|
struct event_base *base = event_base_new();
|
2010-09-25 20:34:22 +00:00
|
|
|
|
2010-10-11 16:26:38 +00:00
|
|
|
redisContext *c = redisLibEventConnect("127.0.0.1", 6379, errorCallback, base);
|
2010-10-07 15:48:03 +00:00
|
|
|
if (c == NULL) return 1;
|
2010-09-25 20:34:22 +00:00
|
|
|
|
|
|
|
redisCommand(c, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
|
2010-10-07 15:48:03 +00:00
|
|
|
redisCommandWithCallback(c, getCallback, "end-1", "GET key");
|
2010-10-11 16:26:38 +00:00
|
|
|
event_base_dispatch(base);
|
2010-10-07 15:48:03 +00:00
|
|
|
redisFree(c);
|
2010-09-25 20:34:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|