Add database switch in config file.

master
Nicolas Favre-Felix 14 years ago
parent 064c701160
commit 0bb096a83e

@ -35,6 +35,7 @@ conf_read(const char *filename) {
conf->logfile = "webdis.log"; conf->logfile = "webdis.log";
conf->verbosity = WEBDIS_NOTICE; conf->verbosity = WEBDIS_NOTICE;
conf->daemonize = 0; conf->daemonize = 0;
conf->database = 0;
j = json_load_file(filename, 0, &error); j = json_load_file(filename, 0, &error);
if(!j) { if(!j) {
@ -78,6 +79,8 @@ conf_read(const char *filename) {
else conf->verbosity = (log_level)tmp; else conf->verbosity = (log_level)tmp;
} else if(strcmp(json_object_iter_key(kv), "daemonize") == 0 && json_typeof(jtmp) == JSON_TRUE) { } else if(strcmp(json_object_iter_key(kv), "daemonize") == 0 && json_typeof(jtmp) == JSON_TRUE) {
conf->daemonize = 1; conf->daemonize = 1;
} else if(strcmp(json_object_iter_key(kv), "database") == 0 && json_typeof(jtmp) == JSON_INTEGER) {
conf->database = json_integer_value(jtmp);
} }
} }

@ -18,6 +18,9 @@ struct conf {
/* daemonize process, off by default */ /* daemonize process, off by default */
int daemonize; int daemonize;
/* database number */
int database;
/* ACL */ /* ACL */
struct acl *perms; struct acl *perms;

@ -76,6 +76,9 @@ on_timer_reconnect(int fd, short event, void *ctx) {
if (s->cfg->redis_auth) { /* authenticate. */ if (s->cfg->redis_auth) { /* authenticate. */
redisAsyncCommand(s->ac, NULL, NULL, "AUTH %s", s->cfg->redis_auth); 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 void

@ -9,6 +9,8 @@
"daemonize": false, "daemonize": false,
"database": 0,
"acl": [ "acl": [
{ {
"disabled": ["DEBUG"] "disabled": ["DEBUG"]

Loading…
Cancel
Save