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-19 14:48:19 +00:00
|
|
|
void errorCallback(const redisContext *c) {
|
2010-10-07 15:48:03 +00:00
|
|
|
printf("Error: %s\n", c->error);
|
2010-09-25 20:34:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-19 18:13:10 +00:00
|
|
|
redisContext *c = libeventRedisConnect(base, errorCallback, "127.0.0.1", 6379);
|
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;
|
|
|
|
}
|