Skip to content

Commit 6dc57bf

Browse files
authored
close #43. Changed graph creation and docs. (#44)
* close #43. Changed graph creation.
1 parent 7d61aff commit 6dc57bf

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/graph.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const redis = require("redis"),
77
* RedisGraph client
88
*/
99
class Graph {
10-
/**
11-
* Creates a client to a specific graph running on the specific host/post
12-
* See: node_redis for more options on createClient
13-
*
14-
* @param {string} graphId the graph id
15-
* @param {string | RedisClient} [host] Redis host or node_redis client
16-
* @param {string} [port] Redis port
17-
* @param {ClientOpts} [options] node_redis options
18-
*/
10+
/**
11+
* Creates a client to a specific graph running on the specific host/post
12+
* See: node_redis for more options on createClient
13+
*
14+
* @param {string} graphId the graph id
15+
* @param {string | RedisClient} [host] Redis host or node_redis client
16+
* @param {string | int} [port] Redis port
17+
* @param {ClientOpts} [options] node_redis options
18+
*/
1919
constructor(graphId, host, port, options) {
2020
this._graphId = graphId; // Graph ID
2121
this._labels = []; // List of node labels.
@@ -29,7 +29,7 @@ class Graph {
2929
let client =
3030
host instanceof redis.RedisClient
3131
? host
32-
: redis.createClient.apply(redis, [].slice.call(arguments, 1));
32+
: redis.createClient(port, host, options);
3333
this._sendCommand = util.promisify(client.send_command).bind(client);
3434
}
3535

test/redisGraphAPITest.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@ const assert = require("assert"),
1010
deepEqual = require("deep-equal");
1111

1212
describe("RedisGraphAPI Test", () => {
13+
// Assuming this test is running against redis server at: localhost:6379 with no password.
1314
const api = new RedisGraph("social");
1415

1516
beforeEach(() => {
1617
return api.deleteGraph().catch(() => {});
1718
});
1819

19-
it("test bring your client", () => {
20-
return new RedisGraph("social", redis.createClient());
20+
it("test connection from port and host", async () => {
21+
// Assuming this test is running against redis server at: localhost:6379 with no password.
22+
let graph = new RedisGraph("social", "127.0.0.1", 6379, {password:undefined});
23+
let result = await graph.query("CREATE ({name:'roi', age:34})");
24+
assert.ok(!result.hasNext());
25+
assert.equal(1, result.getStatistics().nodesCreated());
26+
graph.deleteGraph();
27+
})
28+
29+
it("test connection from client", async () => {
30+
// Assuming this test is running against redis server at: localhost:6379 with no password.
31+
let graph = new RedisGraph("social", redis.createClient());
32+
let result = await graph.query("CREATE ({name:'roi', age:34})");
33+
assert.ok(!result.hasNext());
34+
assert.equal(1, result.getStatistics().nodesCreated());
35+
graph.deleteGraph();
2136
});
2237

2338
it("test Create Node", async () => {

0 commit comments

Comments
 (0)