Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increment a node attribute in RedisGraph

In vanilla Redis I can INCR a numeric key to increase it by one. Can I do the same with a RedisGraph attribute?

like image 747
JRideout Avatar asked May 23 '26 10:05

JRideout


1 Answers

To increment the value of a property in your graph you have to use Cipher itself.

Using this very basic example:

Create a new product in demograph:

GRAPH.QUERY demograph "CREATE (:Product {sku:'abc-001' , description:'acme product', stock: 100}   )"

Get the stock:

GRAPH.QUERY demograph "MATCH (p:Product {sku:'abc-001'}) RETURN p.stock"

1) 1) "p.stock"
2) 1) 1) (integer) 100

Then you can use a query with a Set to update the product stock:

> GRAPH.QUERY demograph "MATCH (p:Product {sku:'abc-001'})  SET   p.stock = p.stock + 1"

1) 1) "Properties set: 1"

Get the stock:

GRAPH.QUERY demograph "MATCH (p:Product {sku:'abc-001'}) RETURN p.stock"

1) 1) "p.stock"
2) 1) 1) (integer) 101

If you do not put a condition, each nodes will be updated.

like image 190
Tug Grall Avatar answered May 27 '26 05:05

Tug Grall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!