more readable redis connect
@@ -216,7 +216,8 @@ static apr_status_t oidc_cache_redis_connect(request_rec *r, oidc_cache_cfg_redi
oidc_cache_cfg_redis_ctx_t *rctx = (oidc_cache_cfg_redis_ctx_t*) context->ctx;
redisReply *reply = NULL;
- if (rctx->rctx == NULL) {
+ if (rctx->rctx != NULL)
+ goto end;
/* no connection, connect to the configured Redis server */
oidc_debug(r, "calling redisConnectWithTimeout");
@@ -226,10 +227,15 @@ static apr_status_t oidc_cache_redis_connect(request_rec *r, oidc_cache_cfg_redi
if ((rctx->rctx == NULL) || (rctx->rctx->err != 0)) {
oidc_error(r, "failed to connect to Redis server (%s:%d): '%s'", rctx->host_str, rctx->port, rctx->rctx != NULL ? rctx->rctx->errstr : "");
oidc_cache_redis_free(context);
- } else {
+ goto end;
+ }
+
/* log the connection */
oidc_debug(r, "successfully connected to Redis server (%s:%d)", rctx->host_str, rctx->port);
+ if (redisSetTimeout(rctx->rctx, context->timeout) != REDIS_OK)
+ oidc_error(r, "redisSetTimeout failed: %s", rctx->rctx->errstr);
+
/* see if we need to authenticate to the Redis server */
if (context->passwd != NULL) {
reply = redisCommand(rctx->rctx, "AUTH %s", context->passwd);
@@ -258,11 +264,7 @@ static apr_status_t oidc_cache_redis_connect(request_rec *r, oidc_cache_cfg_redi
oidc_cache_redis_reply_free(&reply);
}
- if (redisSetTimeout(rctx->rctx, context->timeout) != REDIS_OK)
- oidc_error(r, "redisSetTimeout failed: %s", rctx->rctx->errstr);
-
- }
- }
+end:
return (rctx->rctx != NULL) ? APR_SUCCESS : APR_EGENERAL;
}
