# import redis import redis # import redisgraph from redisgraph import Graph # connect to Redis r = redis.Redis(host='localhost', port=6379) # create a new graph g = Graph('mygraph', r) # create a node person = g.add_node(label='Person', properties={'name': 'John'}) # print the node information print(person.properties)
# import redis import redis # import redisgraph from redisgraph import Graph # connect to Redis r = redis.Redis(host='localhost', port=6379) # create a new graph g = Graph('mygraph', r) # create nodes and edges person1 = g.add_node(label='Person', properties={'name': 'John'}) person2 = g.add_node(label='Person', properties={'name': 'Tom'}) knows = g.add_edge(person1, 'KNOWS', person2) # run a query and print the results query = "MATCH (p:Person)-[:KNOWS]->(q:Person) RETURN p.name, q.name" result = g.query(query) for record in result.result_set: print(record[0], "knows", record[1])Package Library: redisgraph In the above examples, we import the redisgraph module from the package and then create a Redis connection using the Redis module. Then, we create a new graph and add nodes and edges to it. Finally, we run a query on the graph data using the query method and print the results.