-
Notifications
You must be signed in to change notification settings - Fork 6
/
demo.js
39 lines (30 loc) · 1.09 KB
/
demo.js
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
import { createClient } from 'redis'
const client = createClient()
client.on('error', (err) => console.log('Redis Client Error', err))
await client.connect()
let result, query
query = `MATCH (n) RETURN n`
// query = `MATCH (d:Dungeon) RETURN d.name`
// query = `MATCH (r:Room)-[:CONTAINS]->(n) RETURN id(r), r.name, id(n), labels(n), n.name`
// query = `
// MATCH (max:Treasure)
// WITH max(max.gp) AS maxgp
// MATCH (r:Room)-[:CONTAINS]->(t:Treasure)
// WHERE t.gp = maxgp
// WITH id(r) as dest_id
// MATCH p = (start:Room)-[:LEADS_TO*]->(stop:Room)
// WHERE id(start) = 1 AND id(stop) = dest_id
// RETURN p, length(p) as len
// ORDER BY len ASC
// LIMIT 1`
// query = `
// MATCH (max:Treasure)
// WITH max(max.gp) AS maxgp
// MATCH (r:Room)-[:CONTAINS]->(t:Treasure) WHERE t.gp = maxgp
// WITH id(r) as dest_id
// MATCH (start:Room), (stop:Room)
// WHERE id(start) = 1 AND id(stop) = dest_id
// RETURN shortestPath((start)-[:LEADS_TO*]->(stop))`
result = await client.graph.query('dungeon', query)
console.log(JSON.stringify(result))
await client.quit()