mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 11:47:56 +08:00
fix bug when resolving redis server hostname (#1229)
Calling `drogon::app().createRedisClient` from the resolver callback function results in a failure because of `assert(!running_);` in `HttpAppFrameworkImpl::createRedisClient`. This fix uses a promise whose value is set in the callback and the client creation is done outside the callback.
This commit is contained in:
parent
c9c2675ba9
commit
5892fa2f9f
@ -554,12 +554,15 @@ static void loadRedisClients(const Json::Value &redisClients)
|
||||
{
|
||||
if (!redisClients)
|
||||
return;
|
||||
std::promise<std::string> promise;
|
||||
auto future = promise.get_future();
|
||||
for (auto const &client : redisClients)
|
||||
{
|
||||
auto host = client.get("host", "127.0.0.1").asString();
|
||||
trantor::Resolver::newResolver()->resolve(
|
||||
host, [client](const trantor::InetAddress &address) {
|
||||
auto hostIp = address.toIp();
|
||||
host, [&promise](const trantor::InetAddress &address) {
|
||||
promise.set_value(address.toIp());
|
||||
});
|
||||
auto port = client.get("port", 6379).asUInt();
|
||||
auto password = client.get("passwd", "").asString();
|
||||
if (password.empty())
|
||||
@ -575,9 +578,9 @@ static void loadRedisClients(const Json::Value &redisClients)
|
||||
auto isFast = client.get("is_fast", false).asBool();
|
||||
auto timeout = client.get("timeout", -1.0).asDouble();
|
||||
auto db = client.get("db", 0).asUInt();
|
||||
auto hostIp = future.get();
|
||||
drogon::app().createRedisClient(
|
||||
hostIp, port, name, password, connNum, isFast, timeout, db);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user