import time
from py2neo import Graph
from config.neo4j_config import NEO4J_CONFIG_PRO
# NEO4J_CONFIG_PRO = {
# "host": "x.x.x.x",
# "port": ???,
# "user": "xxx",
# "passwd": "xxx"
# }
class Neo4j:
def __init__(self, conf=None):
if conf is None:
conf = {"host": NEO4J_CONFIG_PRO["host"],
"port": NEO4J_CONFIG_PRO['port'],
"auth": (NEO4J_CONFIG_PRO["user"], NEO4J_CONFIG_PRO["passwd"])}
self.__instance = None
for i in range(5): # 最大连接5次
try:
self.__instance = Graph(**conf)
break
except Exception as e:
log.warning(e)
time.sleep(0.2)
def execute_cyp(self, cyp):
if self.__instance is None:
raise Exception("[Connect Error]:con not connect to the neo4j server, please solve")
data = [i.data() for i in self.__instance.run(cyp)]
return data
标签:PRO,instance,Client,conf,NEO4J,Neo4j,CONFIG,self
From: https://www.cnblogs.com/LexLuc/p/17546113.html