2010-10-19 15:10:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <hiredis/libev.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2010-10-19 18:49:37 +00:00
|
|
|
void getCallback(redisContext *c, redisReply *reply, void *privdata) {
|
2010-10-19 19:16:57 +00:00
|
|
|
if (reply == NULL) return; /* Error */
|
2010-10-19 18:49:37 +00:00
|
|
|
printf("argv[%s]: %s\n", (char*)privdata, reply->reply);
|
2010-10-19 15:10:01 +00:00
|
|
|
|
|
|
|
/* Disconnect after receiving the reply to GET */
|
|
|
|
redisDisconnect(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void errorCallback(const redisContext *c) {
|
|
|
|
printf("Error: %s\n", c->error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv) {
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
struct ev_loop *loop = ev_default_loop(0);
|
|
|
|
|
|
|
|
redisContext *c = libevRedisConnect(loop, errorCallback, "127.0.0.1", 6379);
|
|
|
|
if (c == NULL) return 1;
|
|
|
|
|
|
|
|
redisCommand(c, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
|
2010-10-19 18:49:37 +00:00
|
|
|
redisCommandWithCallback(c, getCallback, (char*)"end-1", "GET key");
|
2010-10-19 15:10:01 +00:00
|
|
|
ev_loop(loop, 0);
|
|
|
|
redisFree(c);
|
|
|
|
return 0;
|
|
|
|
}
|