Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import redis
- from redis.commands.graph import Graph, Edge, Node
- import random
- import string
- r = redis.Redis(unix_socket_path='/test_socket.sock')
- g: Graph = r.graph("tg")
- try:
- g.delete()
- except:
- pass
- N1_root = Node(label="N1", properties={"path": "/"})
- N1_A = Node(label="N1", properties={"path": "/A"})
- N1_B = Node(label="N1", properties={"path": "/A/B"})
- N1_C = Node(label="N1", properties={"path": "/A/C"})
- N1_X = Node(label="N1", properties={"path": "/X"})
- g.add_node(N1_root)
- g.add_node(N1_A)
- g.add_node(N1_B)
- g.add_node(N1_C)
- g.add_node(N1_X)
- g.add_edge(Edge(src_node=N1_root, relation="N1PARENT", dest_node=N1_A))
- g.add_edge(Edge(src_node=N1_A, relation="N1PARENT", dest_node=N1_B))
- g.add_edge(Edge(src_node=N1_A, relation="N1PARENT", dest_node=N1_C))
- g.add_edge(Edge(src_node=N1_root, relation="N1PARENT", dest_node=N1_X))
- def gen():
- return ''.join(random.choices(string.ascii_uppercase, k=5))
- nodes = [N1_X]
- for i in range(100):
- parent = random.choice(nodes)
- child_path = parent.properties['path'] + '/' + gen()
- child = Node(label="N1", properties={"path": child_path})
- g.add_node(child)
- g.add_edge(Edge(src_node=parent, relation="N1PARENT", dest_node=child))
- nodes.append(child)
- N2_X = Node(label="N2", properties={"uid": "XXXXX-XXX-XXXX"})
- N3_test = Node(label="N3", properties={"name": "test"})
- g.add_node(N2_X)
- g.add_node(N3_test)
- g.add_edge(Edge(src_node=N2_X, relation="N2_TO_N1", dest_node=N1_root))
- g.add_edge(Edge(src_node=N3_test, relation="N3_TO_N2", dest_node=N2_X))
- g.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement