Fix a bug when a network failure occurs on Redis connections. (#868)

This commit is contained in:
An Tao 2021-05-25 08:33:53 +08:00 committed by GitHub
parent 65a7dadbfb
commit 36fb3b3a40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -265,20 +265,27 @@ void RedisConnection::sendCommandInLoop(
void RedisConnection::handleResult(redisReply *result)
{
LOG_TRACE << "redis reply: " << result->type;
auto commandCallback = std::move(resultCallbacks_.front());
resultCallbacks_.pop();
auto exceptionCallback = std::move(exceptionCallbacks_.front());
exceptionCallbacks_.pop();
if (result->type != REDIS_REPLY_ERROR)
if (result && result->type != REDIS_REPLY_ERROR)
{
commandCallback(RedisResult(result));
}
else
{
exceptionCallback(
RedisException(RedisErrorCode::kRedisError,
std::string{result->str, result->len}));
if (result)
{
exceptionCallback(
RedisException(RedisErrorCode::kRedisError,
std::string{result->str, result->len}));
}
else
{
exceptionCallback(RedisException(RedisErrorCode::kConnectionBroken,
"Network failure"));
}
}
if (resultCallbacks_.empty())
{