from redisgraph import Graph graph_name = 'social' redis_con = Redis(host='localhost', port=6379) graph = Graph(graph_name, redis_con)
query = "MATCH (p:Person)-[:FRIENDS_WITH]->(q:Person) RETURN p,q" result_set = graph.query(query)
query = "CREATE (:Person {name: 'Jack',age: 32})-[:FRIENDS_WITH]->(:Person {name: 'Lucy',age: 27})" graph.query(query)This code snippet creates a new Person node with the name 'Jack' and age 32, and connects it with another Person node named 'Lucy' with the age of 27. The query is executed using the graph.query() method, which inserts the data into the 'social' graph. Overall, Python RedisGraph provides a powerful tool to store and query graph data using Redis as a backend engine. It provides rich querying capabilities, supports multiple programming languages, and scales well for large-scale graph data processing.