In vanilla Redis I can INCR
a numeric key to increase it by one. Can I do the same with a RedisGraph attribute?
Asked
Active
Viewed 438 times
3

JRideout
- 1,635
- 11
- 16
1 Answers
4
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.

Tug Grall
- 3,410
- 1
- 14
- 16