virtual Status Conn()

in tensorflow_recommenders_addons/dynamic_embedding/core/kernels/redis_impl/redis_cluster_connection_pool.hpp [112:153]


  virtual Status Conn() override {
    assert(redis_connection_params.redis_host_ip.size() ==
           redis_connection_params.redis_host_port.size());
    auto role_read = Role::MASTER;
    if (redis_connection_params.redis_read_access_slave) {
      role_read = Role::SLAVE;
    }
    if (isRedisConnect == false) {
      for (size_t i = 0; i < redis_connection_params.redis_host_ip.size();
           ++i) {
        for (short j = 0; j < 10; j++) {
          if (redis_conn_read == nullptr) {
            redis_conn_read = StartConn(i, role_read);
          }
          if (redis_conn_write == nullptr) {
            redis_conn_write = StartConn(i, Role::MASTER);
          }
          if (redis_conn_read != nullptr && redis_conn_write != nullptr) {
            isRedisConnect = true;
            return Status::OK();
          }
        }
        LOG(WARNING) << "Can not access the host "
                     << redis_connection_params.redis_host_ip[i]
                     << ". Delete it from the host list.";
        redis_connection_params.redis_host_ip.erase(
            redis_connection_params.redis_host_ip.begin() + i);
        redis_connection_params.redis_host_port.erase(
            redis_connection_params.redis_host_port.begin() + i);
      }
      if (isRedisConnect == false) {
        LOG(ERROR) << "Can not connect to the Redis Cluster servers.";
        if (redis_conn_read == nullptr && redis_conn_write != nullptr) {
          return Status(error::UNAVAILABLE,
                        "Can not access Redis Slave servers, Exit without any "
                        "Redis connection.");
        }
        return Status(error::UNAVAILABLE, "Exit without any Redis connection.");
      }
    }
    return Status::OK();
  }