diff --git a/conf.c b/conf.c index 6402acb..ac20d5d 100644 --- a/conf.c +++ b/conf.c @@ -35,6 +35,7 @@ conf_read(const char *filename) { conf->logfile = "webdis.log"; conf->verbosity = WEBDIS_NOTICE; conf->daemonize = 0; + conf->database = 0; j = json_load_file(filename, 0, &error); if(!j) { @@ -78,6 +79,8 @@ conf_read(const char *filename) { else conf->verbosity = (log_level)tmp; } else if(strcmp(json_object_iter_key(kv), "daemonize") == 0 && json_typeof(jtmp) == JSON_TRUE) { conf->daemonize = 1; + } else if(strcmp(json_object_iter_key(kv), "database") == 0 && json_typeof(jtmp) == JSON_INTEGER) { + conf->database = json_integer_value(jtmp); } } diff --git a/conf.h b/conf.h index 4ddf8a4..292d646 100644 --- a/conf.h +++ b/conf.h @@ -18,6 +18,9 @@ struct conf { /* daemonize process, off by default */ int daemonize; + /* database number */ + int database; + /* ACL */ struct acl *perms; diff --git a/server.c b/server.c index a3f84a1..41221e8 100644 --- a/server.c +++ b/server.c @@ -76,6 +76,9 @@ on_timer_reconnect(int fd, short event, void *ctx) { if (s->cfg->redis_auth) { /* authenticate. */ redisAsyncCommand(s->ac, NULL, NULL, "AUTH %s", s->cfg->redis_auth); } + if (s->cfg->database) { /* change database. */ + redisAsyncCommand(s->ac, NULL, NULL, "SELECT %d", s->cfg->database); + } } void diff --git a/webdis.json b/webdis.json index 4766261..9dcc98c 100644 --- a/webdis.json +++ b/webdis.json @@ -9,6 +9,8 @@ "daemonize": false, + "database": 0, + "acl": [ { "disabled": ["DEBUG"]