Increment a node attribute in RedisGraph

449 views Asked by At

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

1

There are 1 answers

0
Tug Grall On

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.