From 930abec3c30cc16b7b2ca72b999ec48731bb59cc Mon Sep 17 00:00:00 2001 From: ken Date: Thu, 17 Aug 2023 11:02:31 +0800 Subject: [PATCH] force to ping redis when it is failed --- src/ConnectConnectionPool.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ConnectConnectionPool.cpp b/src/ConnectConnectionPool.cpp index e4ea3e1..d048281 100644 --- a/src/ConnectConnectionPool.cpp +++ b/src/ConnectConnectionPool.cpp @@ -177,12 +177,21 @@ void ConnectConnectionPool::check() if (!mServ->fail() || !mServ->online()) { return; } + int db = 0; if (mServ->activate()) { - auto c = mShareConns.empty() ? nullptr : mShareConns[0]; + auto c = mShareConns.empty() ? nullptr : mShareConns[db]; if (!c) { - return; + c = ConnectConnectionAlloc::create(mServ, true); + c->setDb(db); + ++mStats.connections; + mShareConns[db] = c; + logNotice("h %d create server connection %s %d", + mHandler->id(), c->peer(), c->fd()); } if (c->fd() >= 0) { + // Force share connections to ping redis when redis is failed. + RequestPtr req = RequestAlloc::create(Request::PingServ); + mHandler->handleRequest(req, c); return; } c->reopen();