From 26aa51c3befaa89a19a1de5b9fb9fe4126f26f35 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 21 Apr 2017 23:26:01 +0100 Subject: [PATCH] Add a redis_db setting to the ini file. --- src/main.cpp | 1 + src/response.cpp | 9 ++++++++- src/response.hpp | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 758cd39..cbe3b7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,6 +61,7 @@ namespace { parSettings.add_default("redis_port", "6379"); parSettings.add_default("redis_mode", "sock"); parSettings.add_default("redis_sock", "/tmp/redis.sock"); + parSettings.add_default("redis_db", "0"); parSettings.add_default("base_uri", "http://127.0.0.1"); parSettings.add_default("website_root", "html"); } diff --git a/src/response.cpp b/src/response.cpp index 8827bbe..d48dfd9 100644 --- a/src/response.cpp +++ b/src/response.cpp @@ -22,6 +22,7 @@ #include "duckhandy/stringize.h" #include "pathname/pathname.hpp" #include "list_highlight_langs.hpp" +#include "duckhandy/lexical_cast.hpp" #include #include #include @@ -102,6 +103,7 @@ namespace tawashi { m_resp_value(std::move(parValue)), m_base_uri(parSettings["base_uri"]), //m_page_basename(fetch_page_basename(m_cgi_env)), + m_redis_db(parSettings["redis_db"]), m_website_root(make_root_path(parSettings)), m_page_basename(std::move(parPageBaseName)), m_resp_type(parRespType), @@ -132,8 +134,13 @@ namespace tawashi { {"languages", make_mstch_langmap()} }; - if (m_redis) + if (m_redis) { m_redis->wait_for_connect(); + auto batch = m_redis->make_batch(); + batch.select(dhandy::lexical_cast(m_redis_db)); + batch.client_setname("tawashi_v" STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)); + batch.throw_if_failed(); + } this->on_process(); this->on_mustache_prepare(mustache_context); diff --git a/src/response.hpp b/src/response.hpp index 6e4135f..3232dac 100644 --- a/src/response.hpp +++ b/src/response.hpp @@ -59,6 +59,7 @@ namespace tawashi { cgi::Env m_cgi_env; std::string m_resp_value; boost::string_ref m_base_uri; + boost::string_ref m_redis_db; std::string m_website_root; std::string m_page_basename; Types m_resp_type;