Skip to content

Commit

Permalink
Made redis_common() gracefully recover from disconnect
Browse files Browse the repository at this point in the history
Fix to make vmod_redis reconnect when redis-server has closed the
connection, making hiredis fail with REDIS_ERR_EOF. Connecting is tried
once and the current command re-issued once per call of redis_common().
  • Loading branch information
Luit committed Dec 5, 2011
1 parent 699272c commit a610660
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/vmod_redis.c
Expand Up @@ -81,6 +81,18 @@ redis_common(struct sess *sp, struct vmod_priv *priv, const char *command)
}

reply = redisCommand(c, command);
if (c->err == REDIS_ERR_EOF) {
c = redisConnect(cfg->host, cfg->port);
if (c->err) {
LOG_E("redis error (reconnect): %s\n", c->errstr);
redisFree(c);
} else {
redisFree(pthread_getspecific(redis_key));
(void)pthread_setspecific(redis_key, c);

reply = redisCommand(c, command);
}
}
if (reply == NULL) {
LOG_E("redis error (command): err=%d errstr=%s\n", c->err, c->errstr);
return NULL;
Expand Down

0 comments on commit a610660

Please sign in to comment.