def binary_tree_graph2(): global redis_graph redis_con = _brand_new_redis() redis_graph = Graph(redis_con, "G2") redis_graph.query("CREATE(a: A {name: 'a'}), \ (b1: X {name: 'b1'}), \ (b2: X {name: 'b2'}), \ (b3: X {name: 'b3'}), \ (b4: X {name: 'b4'}), \ (c11: X {name: 'c11'}), \ (c12: Y {name: 'c12'}), \ (c21: X {name: 'c21'}), \ (c22: Y {name: 'c22'}), \ (c31: X {name: 'c31'}), \ (c32: Y {name: 'c32'}), \ (c41: X {name: 'c41'}), \ (c42: Y {name: 'c42'}) \ CREATE(a)-[:KNOWS] -> (b1), \ (a)-[:KNOWS] -> (b2), \ (a)-[:FOLLOWS] -> (b3), \ (a)-[:FOLLOWS] -> (b4) \ CREATE(b1)-[:FRIEND] -> (c11),\ (b1)-[:FRIEND] -> (c12), \ (b2)-[:FRIEND] -> (c21), \ (b2)-[:FRIEND] -> (c22), \ (b3)-[:FRIEND] -> (c31), \ (b3)-[:FRIEND] -> (c32), \ (b4)-[:FRIEND] -> (c41), \ (b4)-[:FRIEND] -> (c42) \ CREATE(b1)-[:FRIEND] -> (b2), \ (b2)-[:FRIEND] -> (b3), \ (b3)-[:FRIEND] -> (b4), \ (b4)-[:FRIEND] -> (b1) \ ")
def empty_graph(): global redis_graph redis_con = _brand_new_redis() redis_graph = Graph(redis_con, "G") # Create a graph with a single node. redis_graph.add_node(Node()) redis_graph.commit() # Delete node to have an empty graph. redis_graph.query("MATCH (n) DELETE n")
def debug(host, port): global redis_con global redis_graph redis_con = redis.Redis(host=host, port=port) redis_graph = Graph(redis_con, social_utils.graph_name) print("populate_graph") social_utils.populate_graph(redis_con, redis_graph) print("run_queries") run_queries()
def main(argv): global redis_con global redis_graph parser = argparse.ArgumentParser(description='Social demo.', add_help=False) parser.add_argument('-h', '--host', dest='host', help='redis host') parser.add_argument('-p', '--port', dest='port', type=int, help='redis port') parser.add_argument("--debug", action='store_const', const=True) args = parser.parse_args() if args.debug is not None: debug('127.0.0.1', 6379) elif args.host is not None and args.port is not None: debug(args.host, args.port) else: with _redis() as redis_con: redis_graph = Graph(redis_con, imdb_utils.graph_name) imdb_utils.populate_graph(redis_con, redis_graph) run_queries()
def make_connection(): env = Env(decodeResponses=True, module=os.path.join(ROOT, "src/redisgraph.so"), logDir="logs") redis_con = env.getConnection() return Graph(redis_con, "G")