diff --git a/daemon/redis.c b/daemon/redis.c index 2d8064425..039d66f9b 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -293,6 +293,8 @@ err2: endpoint_print_buf(&r->endpoint), r->ctx->errstr); return -1; } + redisFree(r->ctx); + r->ctx = NULL; err: rlog(LOG_ERR, "Failed to connect to Redis %s", endpoint_print_buf(&r->endpoint)); @@ -617,7 +619,7 @@ void redis_notify_loop(void *d) { next_run = rtpe_now.tv_sec + seconds; - if (redis_check_conn(r) == REDIS_STATE_RECONNECTED || redis_notify_return < 0) { + if (redis_check_conn(r) == REDIS_STATE_CONNECTED || redis_notify_return < 0) { redis_disconnect(); // alloc new redis async context upon redis breakdown if (redis_async_context_alloc() < 0) { @@ -719,7 +721,7 @@ static int redis_check_conn(struct redis *r) { ilog(LOG_INFO, "RE-Establishing connection for Redis server %s",endpoint_print_buf(&r->endpoint)); // try redis connection - if (redisCommandNR(r->ctx, "PING") == 0) { + if (r->ctx && redisCommandNR(r->ctx, "PING") == 0) { // redis is connected return REDIS_STATE_CONNECTED; } @@ -748,7 +750,7 @@ static int redis_check_conn(struct redis *r) { } // redis is re-connected - return REDIS_STATE_RECONNECTED; + return REDIS_STATE_CONNECTED; } /* called with r->lock held and c->master_lock held */ diff --git a/include/redis.h b/include/redis.h index 864a7e668..fccfa1a19 100644 --- a/include/redis.h +++ b/include/redis.h @@ -26,9 +26,8 @@ enum redis_role { }; enum redis_state { - REDIS_STATE_DISCONNECTED = 0, // DISCONNECTED -> DISCONNECTED - REDIS_STATE_CONNECTED, // CONNECTED -> CONNECTED - REDIS_STATE_RECONNECTED, // DISCONNECTED -> CONNECTED + REDIS_STATE_DISCONNECTED = 0, + REDIS_STATE_CONNECTED, }; enum event_base_action {