diff --git a/lib/incredis b/lib/incredis index 772e039..1d7a89f 160000 --- a/lib/incredis +++ b/lib/incredis @@ -1 +1 @@ -Subproject commit 772e039078efe8d9ea2f77c994984858da49eb6f +Subproject commit 1d7a89fee3a8d56db805e7515cee24aaa1fe3036 diff --git a/src/main.cpp b/src/main.cpp index 1595f96..0516188 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,11 +49,26 @@ namespace { full_path.join(TAWASHI_CONFIG_FILE); return full_path.path(); } + + redis::IncRedis make_incredis (const tawashi::IniFile::KeyValueMapType& parSettings) { + using redis::IncRedis; + + if (parSettings.at("redis_mode") == "inet") { + return IncRedis( + std::string(parSettings.at("redis_server")), + dhandy::lexical_cast(parSettings.at("redis_port")) + ); + } + else if (parSettings.at("redis_mode") == "sock") { + return IncRedis(std::string(parSettings.at("redis_sock"))); + } + else { + throw std::runtime_error("Unknown setting for \"redis_mode\", valid settings are \"inet\" or \"sock\""); + } + } } //unnamed namespace int main() { - //std::cout << "Content-type:text/plain\n\n"; - #if !defined(NDEBUG) std::cerr << "Loading config: \"" << config_file_path() << "\"\n"; #endif @@ -63,7 +78,7 @@ int main() { conf.close(); const auto& settings = ini.parsed().at("tawashi"); - redis::IncRedis incredis(std::string(settings.at("redis_server")), dhandy::lexical_cast(settings.at("redis_port"))); + auto incredis = make_incredis(settings); incredis.connect(); tawashi::cgi::Env cgi_env;