nebula_kg.py 817 B

123456789101112131415161718192021222324
  1. from nebula3.gclient.net import ConnectionPool
  2. from nebula3.Config import Config
  3. class NebulaConn:
  4. def initConnect(self, host, port, username, password, graphSpace):
  5. # 定义配置
  6. config = Config()
  7. config.max_connection_pool_size = 10
  8. # 初始化连接池
  9. connection_pool = ConnectionPool()
  10. # 如果给定的服务器正常,则返回true,否则返回false。
  11. status = connection_pool.init([(host, port)], config)
  12. # 用户名与密码
  13. session = connection_pool.get_session(username, password)
  14. session.execute('USE %s' %(graphSpace))
  15. return session, connection_pool
  16. def releaseConnectionPool(self, connection_pool):
  17. connection_pool.close()
  18. def releaseSession(self, session):
  19. session.release()