summaryrefslogtreecommitdiff
path: root/libev-example.c
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-10-19 17:10:01 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-10-19 21:24:24 +0200
commite245ab48ec8f766e589771b976761a0a41b6442d (patch)
treea1412036f29a8d6fce9a0e1f08aa5c2c8ebd6596 /libev-example.c
parent206868de060bbfeb2745dad2f410691ad2fc62f8 (diff)
Added header file and example for usage from libev
Diffstat (limited to 'libev-example.c')
-rw-r--r--libev-example.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/libev-example.c b/libev-example.c
new file mode 100644
index 0000000..8c48121
--- /dev/null
+++ b/libev-example.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <hiredis/libev.h>
+#include <signal.h>
+
+void getCallback(redisContext *c, redisReply *reply, const void *privdata) {
+ printf("argv[%s]: %s\n", (const char*)privdata, reply->reply);
+
+ /* 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]));
+ redisCommandWithCallback(c, getCallback, "end-1", "GET key");
+ ev_loop(loop, 0);
+ redisFree(c);
+ return 0;
+}