diff options
author | Gergely Nagy <algernon@madhouse-project.org> | 2013-11-30 11:02:14 +0100 |
---|---|---|
committer | Jan-Erik Rediger <janerik@fnordig.de> | 2015-07-27 22:48:05 +0200 |
commit | 3b153cbf9dda2c61af26ad8df2a31b8a5d6a38c8 (patch) | |
tree | 5d08cc94c61c3af9021e257bbf1b50404775137b /examples/example-ivykis.c | |
parent | 2fc31e74b124962454b46ae3def3addc6b2db090 (diff) |
Add an Ivykis adapter
This adds a new adapter and an example for using hiredis with the ivykis
async I/O library.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Diffstat (limited to 'examples/example-ivykis.c')
-rw-r--r-- | examples/example-ivykis.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/example-ivykis.c b/examples/example-ivykis.c new file mode 100644 index 0000000..67affce --- /dev/null +++ b/examples/example-ivykis.c @@ -0,0 +1,58 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> + +#include <hiredis.h> +#include <async.h> +#include <adapters/ivykis.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); + + iv_init(); + + redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379); + if (c->err) { + /* Let *c leak for now... */ + printf("Error: %s\n", c->errstr); + return 1; + } + + redisIvykisAttach(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"); + + iv_main(); + + iv_deinit(); + + return 0; +} |