diff --git a/lib/redis/rediswriter.cpp b/lib/redis/rediswriter.cpp index 010499387..0674f9d62 100644 --- a/lib/redis/rediswriter.cpp +++ b/lib/redis/rediswriter.cpp @@ -42,6 +42,8 @@ void RedisWriter::Start(bool runtimeCreated) m_ConfigDumpInProgress = false; + m_WorkQueue.SetExceptionCallback(boost::bind(&RedisWriter::ExceptionHandler, this, _1)); + m_ReconnectTimer = new Timer(); m_ReconnectTimer->SetInterval(15); m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&RedisWriter::ReconnectTimerHandler, this)); @@ -57,6 +59,19 @@ void RedisWriter::Start(bool runtimeCreated) thread.detach(); } +void RedisWriter::ExceptionHandler(boost::exception_ptr exp) +{ + Log(LogCritical, "RedisWriter", "Exception during redis query. Verify that Redis is operational."); + + Log(LogDebug, "RedisWriter") + << "Exception during redis operation: " << DiagnosticInformation(exp); + + if (m_Context) { + redisFree(m_Context); + m_Context = NULL; + } +} + void RedisWriter::ReconnectTimerHandler(void) { m_WorkQueue.Enqueue(boost::bind(&RedisWriter::TryToReconnect, this)); @@ -275,7 +290,7 @@ boost::shared_ptr RedisWriter::ExecuteQuery(const std::vectortype == REDIS_REPLY_ERROR) { - Log(LogInformation, "RedisWriter") + Log(LogCritical, "RedisWriter") << "Redis query failed: " << reply->str; String msg = reply->str; diff --git a/lib/redis/rediswriter.hpp b/lib/redis/rediswriter.hpp index a32304f0b..04af7c520 100644 --- a/lib/redis/rediswriter.hpp +++ b/lib/redis/rediswriter.hpp @@ -82,6 +82,8 @@ private: void AssertOnWorkQueue(void); + void ExceptionHandler(boost::exception_ptr exp); + boost::shared_ptr ExecuteQuery(const std::vector& query); Timer::Ptr m_ReconnectTimer;