2010-09-25 20:34:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-10-10 18:51:27 +00:00
|
|
|
#include <signal.h>
|
2010-11-01 09:42:32 +00:00
|
|
|
#include "hiredis.h"
|
|
|
|
#include "async.h"
|
|
|
|
#include "adapters/libevent.h"
|
2010-09-25 20:34:22 +00:00
|
|
|
|
2010-11-01 09:17:28 +00:00
|
|
|
void getCallback(redisAsyncContext *c, redisReply *reply, void *privdata) {
|
2010-11-01 10:11:43 +00:00
|
|
|
if (reply == NULL) return;
|
2010-11-01 09:17:28 +00:00
|
|
|
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
|
2010-09-25 20:34:22 +00:00
|
|
|
|
2010-10-07 15:48:03 +00:00
|
|
|
/* Disconnect after receiving the reply to GET */
|
2010-11-01 09:17:28 +00:00
|
|
|
redisAsyncDisconnect(c);
|
2010-09-25 20:34:22 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 09:17:28 +00:00
|
|
|
void disconnectCallback(const redisAsyncContext *c, int status) {
|
|
|
|
if (status != REDIS_OK) {
|
|
|
|
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-11-01 09:17:28 +00:00
|
|
|
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
|
|
|
|
if (c->error != NULL) {
|
|
|
|
/* Let *c leak for now... */
|
|
|
|
printf("Error: %s\n", c->error);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-09-25 20:34:22 +00:00
|
|
|
|
2010-11-01 09:17:28 +00:00
|
|
|
redisLibeventAttach(c,base);
|
|
|
|
redisAsyncSetDisconnectCallback(c,disconnectCallback);
|
|
|
|
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
|
|
|
|
redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
|
2010-10-11 16:26:38 +00:00
|
|
|
event_base_dispatch(base);
|
2010-09-25 20:34:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|