12345678910111213141516171819202122 |
- from neo4j import GraphDatabase
- from app.config.config import Config
- class Neo4jDriver:
- def __init__(self):
- self._driver = GraphDatabase.driver(
- Config.NEO4J_URI,
- auth=(Config.NEO4J_USER, Config.NEO4J_PASSWORD),
- encrypted=Config.NEO4J_ENCRYPTED,
- max_connection_pool_size=20, # 根据负载调整
- connection_timeout=30, # 秒
- connection_acquisition_timeout=60 # 秒
- )
-
- def get_session(self):
- return self._driver.session()
-
- def close(self):
- self._driver.close()
- # 单例实例
- neo4j_driver = Neo4jDriver()
|