diff options
-rw-r--r-- | extra/hiredis/libevent.h | 5 | ||||
-rw-r--r-- | libevent-example.c | 7 |
2 files changed, 5 insertions, 7 deletions
diff --git a/extra/hiredis/libevent.h b/extra/hiredis/libevent.h index 63d6663..46b5503 100644 --- a/extra/hiredis/libevent.h +++ b/extra/hiredis/libevent.h @@ -3,7 +3,7 @@ #include <hiredis.h> /* Prototype for the error callback. */ -typedef void (redisErrorCallback)(redisContext*); +typedef void (redisErrorCallback)(const redisContext*); /* This struct enables us to pass both the events and the * redisContext to the read and write handlers. */ @@ -73,11 +73,12 @@ void redisLibEventOnFree(redisContext *c, void *privdata) { free(e); } -redisContext *redisLibEventConnect(const char *ip, int port, redisErrorCallback *err, struct event_base *base) { +redisContext *redisLibEventConnect(struct event_base *base, redisErrorCallback *err, const char *ip, int port) { redisEvents *e; redisContext *c = redisConnectNonBlock(ip, port, NULL); if (c->error != NULL) { err(c); + redisFree(c); return NULL; } diff --git a/libevent-example.c b/libevent-example.c index dd36604..0acdd3f 100644 --- a/libevent-example.c +++ b/libevent-example.c @@ -11,18 +11,15 @@ void getCallback(redisContext *c, redisReply *reply, const void *privdata) { redisDisconnect(c); } -void errorCallback(redisContext *c) { +void errorCallback(const redisContext *c) { printf("Error: %s\n", c->error); - - /* Clean up the context when there was an error */ - redisFree(c); } int main (int argc, char **argv) { signal(SIGPIPE, SIG_IGN); struct event_base *base = event_base_new(); - redisContext *c = redisLibEventConnect("127.0.0.1", 6379, errorCallback, base); + redisContext *c = redisLibEventConnect(base, errorCallback, "127.0.0.1", 6379); if (c == NULL) return 1; redisCommand(c, "SET key %b", argv[argc-1], strlen(argv[argc-1])); |