Fix an error when constructing RedisClientImpl objects (#840)

This commit is contained in:
An Tao 2021-05-05 09:51:04 +08:00 committed by GitHub
parent cb1876f26b
commit f99c72bd5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,14 +38,17 @@ RedisClientImpl::RedisClientImpl(const trantor::InetAddress &serverAddress,
numberOfConnections_(numberOfConnections)
{
loops_.start();
for (size_t i = 0; i < numberOfConnections_; ++i)
{
auto loop = loops_.getNextLoop();
loop->queueInLoop([this, loop]() {
std::lock_guard<std::mutex> lock(connectionsMutex_);
connections_.insert(newConnection(loop));
});
}
std::thread([this]() {
for (size_t i = 0; i < numberOfConnections_; ++i)
{
auto loop = loops_.getNextLoop();
loop->queueInLoop([this, loop]() {
std::lock_guard<std::mutex> lock(connectionsMutex_);
connections_.insert(newConnection(loop));
});
}
}).detach();
}
RedisConnectionPtr RedisClientImpl::newConnection(trantor::EventLoop *loop)
@ -395,4 +398,4 @@ void RedisClientImpl::execCommandAsyncWithTimeout(
tasks_.emplace_back(bfCbPtr);
}
timeoutFlagPtr->runTimer();
}
}