MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / connect

Method connect

imperative/src/impl/persistent_cache.cpp:19–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17 }
18
19 void connect(std::string ip, size_t port, std::optional<std::string> password) {
20 if (password) {
21 m_client.auth(*password);
22 }
23 m_client.connect(
24 ip, port,
25 [](const std::string& host, std::size_t port,
26 cpp_redis::connect_state status) {
27 if (status == cpp_redis::connect_state::dropped) {
28 mgb_log("client disconnected from %s.", host.c_str());
29 mgb_log("Redis server connect to %s :%zu failed.", host.c_str(),
30 port);
31 }
32 },
33 std::uint32_t(200));
34 mgb_assert(m_client.is_connected(), "connect failed");
35 auto flag = m_client.get("mgb-cache-flag");
36 sync();
37 auto is_valid = [](const cpp_redis::reply& reply) {
38 switch (reply.get_type()) {
39 case cpp_redis::reply::type::error:
40 case cpp_redis::reply::type::null:
41 return false;
42 case cpp_redis::reply::type::integer:
43 return reply.as_integer() != 0;
44 case cpp_redis::reply::type::simple_string:
45 case cpp_redis::reply::type::bulk_string:
46 return !reply.as_string().empty();
47 case cpp_redis::reply::type::array:
48 return !reply.as_array().empty();
49 default:
50 mgb_assert(false, "unknown reply type %d", (int)reply.get_type());
51 }
52 };
53 mgb_assert(is_valid(flag.get()), "invalid mgb-cache-flag");
54 }
55
56 bool valid() const override { return m_client.is_connected(); }
57

Callers 3

make_from_configMethod · 0.45
workMethod · 0.45
new_socketMethod · 0.45

Calls 4

syncFunction · 0.85
getMethod · 0.45
get_typeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected