Created
December 4, 2011 14:33
-
-
Save Luit/1430331 to your computer and use it in GitHub Desktop.
A simple patch to fix libvmod-redis from completely halting to function after redis-server closes the connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/vmod_redis.c b/src/vmod_redis.c | |
index b59652b..7c0544e 100644 | |
--- a/src/vmod_redis.c | |
+++ b/src/vmod_redis.c | |
@@ -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) { | |
+ // It seems Redis has disconnected the client, let's try to | |
+ // reconnect and try running the command once more | |
+ c = redisConnect(cfg->host, cfg->port); | |
+ if (c->err) { | |
+ LOG_E("redis error (reconnect): %s\n", c->errstr); | |
+ } else { | |
+ // redisFree(pthread_getspecific(redis_key)); // should I do this here? | |
+ (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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment