-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathredisGraph.ts
More file actions
53 lines (50 loc) · 1.3 KB
/
redisGraph.ts
File metadata and controls
53 lines (50 loc) · 1.3 KB
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
46
47
48
49
50
51
52
53
import redis, { ClientOpts, RedisClient } from "redis";
import util from "util";
import { ResultSet } from "./resultSet";
/**
* RedisGraph client
*/
export class RedisGraph {
private _graphId: string;
private _sendCommand: (arg1: string, options: any) => Promise<void>;
/**
* Creates a client to a specific graph running on the specific host/post
* See: node_redis for more options on createClient
*
* @param graphId the graph id
* @param host Redis host or node_redis client
* @param port Redis port
* @param options node_redis options
*/
constructor(graphId: string, host?: string | RedisClient, port=6379, options?: ClientOpts) {
this._graphId = graphId;
let client =
host instanceof redis.RedisClient
? host
: redis.createClient(port, host, options);
this._sendCommand = util.promisify(client.send_command).bind(client);
}
/**
* Execute a Cypher query
*
* @param query Cypher query
* @return a result set
*/
query(query: string) {
return this._sendCommand("graph.QUERY", [this._graphId, query]).then(
res => {
return new ResultSet(res);
}
);
}
/**
* Deletes the entire graph
*
* @return delete running time statistics
*/
deleteGraph() {
return this._sendCommand("graph.DELETE", [this._graphId]).then(res => {
return new ResultSet(res);
});
}
}