import redis from redisgraph import Node, Edge, Graph # connect to Redis r = redis.Redis(host='localhost', port=6379) # create a new graph graph = Graph('mygraph', r) # start a new transaction transaction = graph.multi() # create two nodes alice = Node(label='person', properties={'name': 'Alice'}) bob = Node(label='person', properties={'name': 'Bob'}) # create an edge between the nodes knows = Edge(alice, 'knows', bob) # add the nodes and edge to the transaction transaction.add_node(alice) transaction.add_node(bob) transaction.add_edge(knows) # commit the changes transaction.commit()
import redis from redisgraph import Node, Graph # connect to Redis r = redis.Redis(host='localhost', port=6379) # create a new graph graph = Graph('mygraph', r) # start a new transaction transaction = graph.multi() # get the existing node alice = Node(label='person', properties={'name': 'Alice'}) existing_node = graph.query("MATCH (n:person {name: 'Alice'}) RETURN n")[0]['n'] # update the properties of the node existing_node.properties['age'] = 30 # add the updated node to the transaction transaction.update_node(existing_node) # commit the changes transaction.commit()In this example, a new graph is created and a transaction is started using the `multi()` method. An existing node is retrieved from the graph using a Cypher query, and its properties are updated by modifying the `properties` dictionary. The updated node is added to the transaction using the `update_node()` method, and the changes are committed to the graph using the `commit()` method.