Merge keep-alive contrib

Integrated as a merge commit to preserve the author's commit signatures.
master
Nicolas Favre-Felix 1 year ago
commit 90b8e2c023
No known key found for this signature in database
GPG Key ID: C04E7AA8B6F73372

@ -31,6 +31,9 @@ conf_auth_legacy(char *password);
static struct auth *
conf_auth_username_password(json_t *jarray);
static void
conf_parse_hiredis(struct conf *conf, json_t *jhiredis);
int
conf_str_allcaps(const char *s, const size_t sz) {
size_t i;
@ -211,6 +214,8 @@ conf_read(const char *filename) {
} else if(strcmp(json_object_iter_key(kv), "ssl") == 0 && json_typeof(jtmp) == JSON_OBJECT) {
conf_parse_ssl(conf, jtmp, filename);
#endif
} else if(strcmp(json_object_iter_key(kv), "hiredis") == 0 && json_typeof(jtmp) == JSON_OBJECT) {
conf_parse_hiredis(conf, jtmp);
} else {
fprintf(stderr, "Warning! Unexpected key or incorrect value in %s: '%s'\n", filename, json_object_iter_key(kv));
}
@ -420,3 +425,16 @@ conf_auth_username_password(json_t *jarray) {
ret->password = password;
return ret;
}
static void
conf_parse_hiredis(struct conf *conf, json_t *jhiredis) {
for(void *kv = json_object_iter(jhiredis); kv; kv = json_object_iter_next(jhiredis, kv)) {
json_t *jtmp = json_object_iter_value(kv);
const char *key = json_object_iter_key(kv);
if(strcmp(key, "keep_alive_sec") == 0 && json_typeof(jtmp) == JSON_INTEGER) {
conf->hiredis_opts.keep_alive_sec = (int)json_integer_value(jtmp);
} else {
fprintf(stderr, "Config error under 'hiredis': unknown key '%s'.", key);
}
}
}

@ -52,6 +52,11 @@ struct conf {
int period_millis; /* only used with LOG_FSYNC_MILLIS */
} log_fsync;
/* HiRedis options */
struct {
int keep_alive_sec; /* passed to redisEnableKeepAliveWithInterval, > 0 to enable */
} hiredis_opts;
#ifdef HAVE_SSL
/* SSL */
struct {

@ -911,11 +911,13 @@ int redisSetTimeout(redisContext *c, const struct timeval tv) {
return REDIS_ERR;
}
int redisEnableKeepAliveWithInterval(redisContext *c, int interval) {
return redisKeepAlive(c, interval);
}
/* Enable connection KeepAlive. */
int redisEnableKeepAlive(redisContext *c) {
if (redisKeepAlive(c, REDIS_KEEPALIVE_INTERVAL) != REDIS_OK)
return REDIS_ERR;
return REDIS_OK;
return redisKeepAlive(c, REDIS_KEEPALIVE_INTERVAL);
}
/* Set a user provided RESP3 PUSH handler and return any old one set. */

@ -298,6 +298,7 @@ int redisReconnect(redisContext *c);
redisPushFn *redisSetPushCallback(redisContext *c, redisPushFn *fn);
int redisSetTimeout(redisContext *c, const struct timeval tv);
int redisEnableKeepAlive(redisContext *c);
int redisEnableKeepAliveWithInterval(redisContext *c, int interval);
void redisFree(redisContext *c);
redisFD redisFreeKeepFd(redisContext *c);
int redisBufferRead(redisContext *c);

@ -124,6 +124,9 @@ server_new(const char *cfg_file) {
s->log.fd = -1;
s->cfg = conf_read(cfg_file);
/* initialize logging as soon as we've read the config file */
slog_init(s);
#ifdef HAVE_SSL
if(s->cfg->ssl.enabled) {
server_init_ssl(s);
@ -262,9 +265,6 @@ server_start(struct server *s) {
/* initialize libevent */
s->base = event_base_new();
/* initialize logging before forking */
slog_init(s);
if(s->cfg->daemonize) {
server_daemonize(s, s->cfg->pidfile);

Loading…
Cancel
Save