/
Graph_7_Northwind_Redis.txt
45 lines (27 loc) · 1.47 KB
/
Graph_7_Northwind_Redis.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Adding Graph Structures - Redis Graph Demo
This code uses the Redisgraph container to implment a partial employee hierarchy using
Redis graph extensions and then deletes it.
Steve Jones, copyright 2022
This code is provided as is for demonstration purposes. It may not be suitable for
your environment. Please test this on your own systems. This code may not be republished
or redistributed by anyone without permission.
You are free to use this code inside of your own organization.
*/
# docker run -p 6379:6379 -it --rm redislabs/redisgraph
# program files \ Redis
# run redis-cli
GRAPH.QUERY Northwind "CREATE (:employee {employeeID: 10, firstName:'Steve', title:'President'})-[:REPORTS_TO]->(:employee {employeeID: 11, firstName:'Tia', title:'CEO'})"
# check the values
GRAPH.QUERY Northwind "MATCH (e:employee { firstName :'Tia' } ) return e"
# two nodes
GRAPH.QUERY Northwind "MATCH (e:employee ) return e"
# is there a relationship
GRAPH.QUERY Northwind "MATCH (e:employee)<-[:REPORTS_TO]-(sub) RETURN sub.firstName as employee, e.firstName as manager"
# add another
GRAPH.QUERY Northwind "CREATE (:employee {firstName:'Andrew', title:'Vice President-Sales'})"
# add relationship
GRAPH.QUERY Northwind "MATCH (e:employee), (m:employee) WHERE e.firstName = 'Andrew' and m.firstName = 'Steve' CREATE (e)-[:REPORTS_TO]->(m)"
# query
GRAPH.QUERY Northwind "MATCH (e:employee)<-[:REPORTS_TO]-(sub) RETURN sub.firstName as employee, e.firstName as manager"
GRAPH.DELETE Northwind