summaryrefslogtreecommitdiff
path: root/deps/hiredis/examples/example-libev.c
diff options
context:
space:
mode:
authorMatt Stancliff <matt@genges.com>2014-04-24 15:14:54 -0400
committerantirez <antirez@gmail.com>2014-06-23 11:44:34 +0200
commit28f32c99d0118eb60b236a0c8a96ea4bd9b7fa5b (patch)
tree393b4873a2dc0a28e9f7110605f4eae672d20b75 /deps/hiredis/examples/example-libev.c
parentef897a41e80eb03a18d131d6a3c4d1d868f38ea0 (diff)
downloadredis-28f32c99d0118eb60b236a0c8a96ea4bd9b7fa5b.tar.gz
hiredis: Update to latest version
This is hiredis f225c276be7fd0646019b51023e3f41566633dfe This update includes all changes that diverged inside of Redis since the last update. This version also allows optional source address binding for connections which we need for some Sentinel deployments.
Diffstat (limited to 'deps/hiredis/examples/example-libev.c')
-rw-r--r--deps/hiredis/examples/example-libev.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/deps/hiredis/examples/example-libev.c b/deps/hiredis/examples/example-libev.c
new file mode 100644
index 000000000..cc8b166ec
--- /dev/null
+++ b/deps/hiredis/examples/example-libev.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+
+#include <hiredis.h>
+#include <async.h>
+#include <adapters/libev.h>
+
+void getCallback(redisAsyncContext *c, void *r, void *privdata) {
+ redisReply *reply = r;
+ if (reply == NULL) return;
+ printf("argv[%s]: %s\n", (char*)privdata, reply->str);
+
+ /* Disconnect after receiving the reply to GET */
+ redisAsyncDisconnect(c);
+}
+
+void connectCallback(const redisAsyncContext *c, int status) {
+ if (status != REDIS_OK) {
+ printf("Error: %s\n", c->errstr);
+ return;
+ }
+ printf("Connected...\n");
+}
+
+void disconnectCallback(const redisAsyncContext *c, int status) {
+ if (status != REDIS_OK) {
+ printf("Error: %s\n", c->errstr);
+ return;
+ }
+ printf("Disconnected...\n");
+}
+
+int main (int argc, char **argv) {
+ signal(SIGPIPE, SIG_IGN);
+
+ redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
+ if (c->err) {
+ /* Let *c leak for now... */
+ printf("Error: %s\n", c->errstr);
+ return 1;
+ }
+
+ redisLibevAttach(EV_DEFAULT_ c);
+ redisAsyncSetConnectCallback(c,connectCallback);
+ 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");
+ ev_loop(EV_DEFAULT_ 0);
+ return 0;
+}