diff options
Diffstat (limited to 'hiredis.c')
-rw-r--r-- | hiredis.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -586,6 +586,13 @@ static redisContext *redisContextInit(redisReplyFunctions *fn) { return c; } +void redisDisconnect(redisContext *c) { + if (c->cbDisconnect != NULL) + c->cbDisconnect(c,c->privdataDisconnect); + close(c->fd); + c->flags &= ~REDIS_CONNECTED; +} + void redisFree(redisContext *c) { if (c->cbFree != NULL) c->cbFree(c,c->privdataFree); @@ -605,6 +612,7 @@ void redisFree(redisContext *c) { redisContext *redisConnect(const char *ip, int port, redisReplyFunctions *fn) { redisContext *c = redisContextInit(fn); c->flags |= REDIS_BLOCK; + c->flags |= REDIS_CONNECTED; redisContextConnect(c,ip,port); return c; } @@ -612,10 +620,17 @@ redisContext *redisConnect(const char *ip, int port, redisReplyFunctions *fn) { redisContext *redisConnectNonBlock(const char *ip, int port, redisReplyFunctions *fn) { redisContext *c = redisContextInit(fn); c->flags &= ~REDIS_BLOCK; + c->flags |= REDIS_CONNECTED; redisContextConnect(c,ip,port); return c; } +/* Register callback that is triggered when redisDisconnect is called. */ +void redisSetDisconnectCallback(redisContext *c, redisContextCallback *fn, void *privdata) { + c->cbDisconnect = fn; + c->privdataDisconnect = privdata; +} + /* Register callback that is triggered when a command is put in the output * buffer when the context is non-blocking. */ void redisSetCommandCallback(redisContext *c, redisContextCallback *fn, void *privdata) { |